0

I am trying to send an .xlsx file from a software written in python 2.7 to a telegram chat via https using the 'requests' library. If I send an .xlsx without data (only with columns) I have no error while if I send an xlsx with different data inside I get the following error:

Traceback (most recent call last):
  File "<module:project.TelegramBot>", line 68, in SendDocument
  File "C:\Users\SimoneMaffei\.ignition\cache\gwlocalhost_8088\C0\pylib\requests\api.py", line 109, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\SimoneMaffei\.ignition\cache\gwlocalhost_8088\C0\pylib\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Users\SimoneMaffei\.ignition\cache\gwlocalhost_8088\C0\pylib\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\SimoneMaffei\.ignition\cache\gwlocalhost_8088\C0\pylib\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\SimoneMaffei\.ignition\cache\gwlocalhost_8088\C0\pylib\requests\adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))

This is the code:

import traceback
import json
import requests

apiToken = "12345"
chatID = "12345"

def SendDocument():
    result = {'isValid': False, 'result': None}
    try:
        params = {}
        params['chat_id'] = chatID
        params['document'] = 'attach://file'

        files = {'file': open("C:\\Users\\SimoneMaffei\\Desktop\\report.xlsx", "rb")}
        finalURL = "https://api.telegram.org/bot" + apiToken + "/sendDocument"
        httpResult = requests.post(finalURL, data = params, files=files)

        result["isValid"] = True
        result["result"] = httpResult
    except:
        print(traceback.format_exc())

    return result

print(SendDocument())

With Python 3.x I do not have this problem but I cannot use it. Can someone help me and tell me why do I have this problem?

  • from the last line of the error, it looks like the ssl version is to old. here are some links that might help [here](https://github.com/psf/requests/issues/1847), [here](https://stackoverflow.com/questions/44316292/ssl-sslerror-tlsv1-alert-protocol-version), and [here](https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/) – jkr Aug 16 '22 at 15:05
  • okay, thank you, now I have another error, I updated the question with the new error. – Simone Maffei Aug 16 '22 at 15:16

0 Answers0