For those who are using Pushsafer API with Python3, I can share this bit of help code here. Hope others find it useful as well!
Start by adding the "p" parameter to the post fields. Please note that the instructions on h T T ps://w W w.pushsafer.com/en/pushapi are not complete for this.
Code: Select all
from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'https://www.pushsafer.com/api'
post_fields = {
"t" : title,
"m" : message,
"s" : sound,
"v" : vibration,
"i" : icon,
"c" : iconcolor,
"d" : device,
"u" : url,
"ut" : urltitle,
"p" : picture,
"k" : private_key
}
request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
Start by importing base64:
Code: Select all
import base64
Code: Select all
with open(path_to_picture, 'rb') as image_file:
encoded_string = base64.b64encode(image_file.read())
base64coded = encoded_string.decode('ascii')
Code: Select all
picture_base64 = 'data:image/jpeg;base64,' + base64coded
"p" : picture_base64
That's it!
And a big thank you to the Pushsafer developers! Great work!!