skip to Main Content

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


  1. try this one:

    r = requests.post(send_document, data=data, files={'document': a},stream=True)
    
    Login or Signup to reply.
  2. 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()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search