1

SOF,

I saw a thread on reddit about using Python with Pushbullet and thought it would be handy so I'm trying to use Python to send Notifications via PushBullet however I'm running into several problems

1) I'm unable to find out what device each ID is related to...

2) I'm unable to push anything to any device due to the error AttributeError: 'NoneType' object has no attribute 'push_note'

PushBullet.py = https://pypi.python.org/pypi/pushbullet.py/0.4.1
Project Github: https://github.com/randomchars/pushbullet.py

Running the folllowing code:

from pushbullet import PushBullet

pb = PushBullet("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
print pb.devices

phone = pb.get("1234567890")
print phone

push = phone.push_note("This is the title", "This is the body")
print(push.status_code)

Returns:

[Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 1234567890), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 0000000000), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 1111111111), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 2222222222)]
None

Traceback (most recent call last):
  File "C:\Users\Admin\Desktop\PushBullet_Test.py", line 9, in <module>
    push = phone.push_note("This is the title", "This is the body")
AttributeError: 'NoneType' object has no attribute 'push_note'

Please note that their documentation has a syntax error in the push_note example, it shouldn't have a full stop / period before the end bracket.

I can't find any fix anywhere for this problem and can't even find anyone with the problem :(

Ryflex
  • 5,559
  • 25
  • 79
  • 148

2 Answers2

1

Faced the same problem earlier today

Just use this library by Azelphur:

https://github.com/Azelphur/pyPushBullet

Works like a charm.

Modify the import to

"from pushbullet2 import PushBullet"

Save the library file name as "pushbullet2.py" to avoid conflict with "pushbullet.py" (also save new library in same folder). Ensure you download dependencies, all available through pip, listed in Read Me.

from pushbullet2 import PushBullet

pb = PushBullet("ABCDEFGHIJKLMOPQRSTUVWXYZ")

devices = pb.getDevices()
phone = devices[0]["iden"] #change number to change device

#print devices
print phone

push = pb.pushNote(phone,"This is title", "This is the body")
Hesham
  • 21
  • 3
1

I've built (yet) another CLI Tool in Python that allows you to very quickly and easily use Email / Pushover / Pushbullet notifications.

Here you can find source code and documentation:
https://github.com/ltpitt/python-simple-notifications

I will also put here the relevant information for simplicity:

Simple Notifications

Simple Notifications is a cross-platform command line tool that allows to easily send out Email (also with attachment) and push notifications (using Pushover or Pushbullet)

Requirements

  • Python: if you have Linux or Mac you should be good to go and you should skip to the next step, if you're on Windows and you like lazy'n'great you can install Python with a couple clicks from: http://ninite.com
  • Python Pip: here are installation instructions.

How to install

Once Python and Python Pip are installed:

$ git clone https://github.com/ltpitt/python-simple-notifications.git
$ cd python-simple-notifications
$ pip install .

Then customize simple_notifications_config.py with the required Email / Pushbullet / Pushover configuration data. It is easy to understand how if you read the comments in simple_notifications_config.py.

Example simple_notification_config.py path for a Windows 10 installation using Python 2.7:
C:\Python27\Lib\site-packages\simple_notifications\simple_notifications_config.py

Example simple_notification_config.py path for a Windows 10 installation using Python 3.7:
C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python37\Lib\site-packages\simple_notifications

Example simple_notification_config.py path for a Linux installation:
/usr/local/lib/python2.7/dist-packages/simple_notifications/simple_notifications_config.py

As last step remember to make the simple_notification_config.py file readable only for the user that will run the script.

On Windows right click on the file, properties and then customize the permissions tab using this explanation:

https://msdn.microsoft.com/en-us/library/bb727008.aspx

On Linux:

$ chmod 400 /usr/local/lib/python2.7/dist-packages/simple_notifications/simple_notifications_config.py  

Usage

Here's how to display help:

$ simple-notifications --help

Output:

Usage: simple-notifications [OPTIONS] COMMAND [ARGS]...

  Simple Notifications sends out email and push notifications from your
  applications (using Pushbullet or Pushover)

Options:
  --help  Show this message and exit.

Commands:
  email       Send a notification using Email
  pushbullet  Send a notification using Pushbullet
  pushover    Send a notification using Pushover

Pitto
  • 8,229
  • 3
  • 42
  • 51