Search code examples
pythonpython-3.xtornadoasynchttpclient

tornado.httpclient AsyncHTTPClient() python3


I have a strange problem and i hope somebody encountered with it. I'm working with TelegramAPI and i want to POST file using multipart/form-data. File size 32K

data = {'photo': open('test.jpg', 'rb').read()}

Using simple requests python lib i have no problem:

res = requests.post(url, files=data)

BUT

When i try to use

http_client = httpclient.AsyncHTTPClient() 

http_client.fetch(url, method='POST', body=urllib.parse.urlencode(data))

With the same picture

I got an error

tornado.httpclient.HTTPError: HTTP 413: Request Entity Too Large

I don't know why? requests works fine, but not AsyncHTTPClient, help me please


Solution

  • Please check out this demo code. You will see there an example on how to upload files.