0

I have a problem, I need help. I want to use PushBullet in python but I got error.

Here my code:

from pushbullet import PushBullet
from pushbullet import device

apik="myapikey"
pb=PushBullet(apik)
de=pb.devices[0]
success, push = de.push_note("adsadasd","asdasdasd asd asd")

I get this error:

Traceback (most recent call last):
  File "gggg.py", line 6, in <module>
    de = pb.devices[0]
IndexError: list index out of range

How can I solve this problem?

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Berkay E.
  • 35
  • 5

1 Answers1

1

It means that you don't have registered device.

Using for loop, you can push for multiple devices, and will not raise exception even though there's no device.

A possible cause of this is wrong api key specified.

from pushbullet import PushBullet
from pushbullet import device

apik = "myapikey"
pb = PushBullet(apik)
for de in pb.devices:
    success, push = de.push_note("adsadasd","asdasdasd asd asd")

If you want to push only to the first device, make sure that there is at least one device:

...
pb = PushBullet(apik)
if pb.devices:
    db = pb.devices[0]:
    success, push = de.push_note("adsadasd","asdasdasd asd asd")
falsetru
  • 357,413
  • 63
  • 732
  • 636