0

I´m trying to send a file using the code below which results in the following error:

ValueError: too many values to unpack (expected 2)

How can I fix this?

bot_token = ""
bot_chatId = ""

a = open('/home/scrapy/diff.csv', 'rb')
send_document = 'https://api.telegram.org/bot' + bot_token +'/sendDocument?'
data = {
  'chat_id': bot_chatId,
  'parse_mode':'HTML',
  'caption':'This is my file'
   }

r = requests.post(send_document, data=data, files=open('/home/scrapy/diff.csv','rb'),stream=True)
print(r.url)

return r.json()

2 Answers 2

1

try this one:

r = requests.post(send_document, data=data, files={'document': a},stream=True)
Sign up to request clarification or add additional context in comments.

Comments

0

sendDocument method needs 2 required parameters: chat_id and document, you already provided the chat_id, to add the document field you should do :

bot_token = ""
bot_chatId = ""

a = open('/home/scrapy/diff.csv', 'rb')
send_document = 'https://api.telegram.org/bot' + bot_token +'/sendDocument?'
data = {
     'chat_id': bot_chatId,
     'parse_mode':'HTML',
     'caption':'This is my file'
}

r = requests.post(send_document, data=data, 
files={'document': open('/home/scrapy/diff.csv','rb')}, stream=True)
print(r.url)

return r.json()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.