Reputation: 4279
I'm using Django to send notifications to android users and requests library to handle the post request. This is my code snippet where I send the actual request to FCM.
def sendNotification(rule_name):
url = "https://fcm.googleapis.com/fcm/send"
headers = {'Authorization': '********************',
'Content-Type': 'application/json'}
myDict = {"to": "/topics/rules",
"data": {
"rule_name": rule_name
}
}
r = requests.post(url, headers=headers, data=myDict)
print r.status_code
print r.text
However the response that I get when I print the status code and text is:
400 JSON_PARSING_ERROR: Unexpected character (t) at position 0.
Can you please point out what is wrong here with my code?
Upvotes: 0
Views: 1253
Reputation: 483
Can you do something like this?
import json
r = requests.post(url, headers=headers, data=json.dumps(myDict))
Upvotes: 3