muety / telepush

🤖 A simple bot to translate JSON HTTP requests into Telegram push messages
MIT License
497 stars 40 forks source link

Invalid character response using requests in Python #4

Closed dhimmel closed 6 years ago

dhimmel commented 6 years ago

I'm really excited to message myself via MiddleManBot to alert me when trailhead spots open for the John Muir Trail.

I'm calling the public bot in python as follows:

url = "https://middleman.ferdinand-muetsch.de/api/messages"
payload = {
    'recipient_token': my_token,
    'text': my_text,
    'origin': my_app,
}
import requests
response = requests.post(url, data=payload)

I'm getting a response with status code 400, whose text is:

invalid character 'r' looking for beginning of value

Any idea what the issue could be?

muety commented 6 years ago

Hey Daniel, I'm glad my bot can help you! I guess what you described is not an issue with the bot itself. Rather you probably need to tell requests that your payload is JSON-encoded. Try response = requests.post(url, json=payload). If it doesn't work, get back to me.

dhimmel commented 6 years ago

json=payload did the trick! Awesome.