3

im trying to upload file with python-requests

with open('file.zip','rb') as fff:
    up = requests.post(url,files=[('file[]',fff)])

and getting:

UnicodeDecodeError: 'ascii' codec can't decode byte ...

when tried to use unicode(fff) and file was uploaded but then i downloaded it and its only 70 bytes

content of ZIP file opened in notepad:

<open file 'file.zip', mode 'rb' at 0x0000000002F6E030>
  • What's the full stack trace on the error? – Adam Rosenfield Oct 30 '13 at 20:39
  • @AdamRosenfield `Traceback (most recent call last): File "uptest.py", line 25, in files = {'Filedata': unicode(open('w.zip', 'rb').read()),} UnicodeDecodeError: 'ascii' codec can't decode byte 0xdc in position 95: ordinal not in range(128)` –  Oct 30 '13 at 21:58
  • 1
    Well there's your problem, you're calling the [`unicode()` function](http://docs.python.org/2/library/functions.html#unicode) on binary, non-textual data. Remove the call to `unicode()`. – Adam Rosenfield Oct 31 '13 at 01:55
  • As Adam Rosenfield suggests, your problem appears to be in your own code. If you can get a stacktrace showing the problem coming out of Requests, please post it. – Lukasa Oct 31 '13 at 08:05

0 Answers0