how to send photo by telegram bot using multipart/form-data
Try this line of code
status = requests.post("https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=" + data['chat_id'], files=files)
Both answers by Delimitry and Pyae Hlian Moe are correct in the sense that they work, but neither address the actual problem with the code you supplied.
The problem is that data
is defined as:
data = {'chat_id', chat_id}
which is a set (not a dictionary) with two values: a string 'chat_id' and the content of chat_id
, instead of
data = {'chat_id' : chat_id}
which is a dictionary with a key: the string 'chat_id' and a corresponding value stored in chat_id
.
chat_id
can be defined as part of the url, but similarly your original code should work as well - defining data and files as parameters for requests.post()
- as long as both data
and files
variables are dictionaries.