UnicodeDecodeError on a multipart file upload

Since im in python3.3 and requests takes a file-like object as the file argument on a post request, why is there an Unicode error? What should i do to be able to upload a multimedia file using requests?


Questions belong on [StackOverflow](http://stackoverflow.com/questions/tagged/python-requests). In general though, multimedia files will not be Unicode compatible because it will attempt to read sequences of bytes in the file object as Unicode multi-byte sequences instead. Ostensibly there's inherent string addition which is causing this. Regardless, without code to reproduce this with, I'm leaning towards closing this.


Until we get code and a stack trace, I'm closing this.


Oh, how in time! I have the same here.  
Python 2.7, requests latest from Github.

``` Bash
Exception in thread Thread-55:
Traceback (most recent call last):
  File "C:\Program Files\python27\lib\threading.py", line 551, in __bootstrap_inner
    self.run()
  File "C:\Program Files\python27\lib\threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "D:\gitrepos\TheQube\src\transfer_dialogs\transfer_dialogs.py", line 63, in perform_transfer
    r = requests.post(self.url, files = file)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\sessions.py", line 327, in request
    prep = self.prepare_request(req)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\sessions.py", line 265, in prepare_request
    hooks=merge_setting(request.hooks, self.hooks),
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\models.py", line 286, in prepare
    self.prepare_body(data, files)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\models.py", line 417, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "C:\Program Files\python27\lib\site-packages\requests-2.0.1-py2.7.egg\requests\models.py", line 139, in _encode_files
    rf = RequestField(name=k, data=fp.read(),
  File "C:\Program Files\python27\lib\codecs.py", line 671, in read
    return self.reader.read(size)
  File "C:\Program Files\python27\lib\codecs.py", line 477, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc5 in position 21: invalid continuation byte
```


@Oire can you give more details than that? What kind of file are you trying to post? Any other details? 


I'm trying to post MP3 files with either Cyrillic names (like _Я сюда ещё вернусь.mp3_) or with extended latin names (like _Mànran — Oran na cloiche.mp3_).  
When I'm debugging, I see these names as \u-something sequences, like this one:

``` Bash
Sun Nov 10, 2013 22:27:11 transfer_dialogs DEBUG: File: {'file': <open file u'D:\\playlists\\Collection\\Russian\\\u0425\u0443\u0443\u043d \u0425\u0443\u0443\u0440 \u0422\u0443 - \u0415\u0441\u043b\u0438 \u0431\u044b \u044f \u0431\u044b\u043b \u0440\u043e\u0436\u0434\u0435\u043d \u043e\u0440\u043b\u043e\u043c.mp3', mode 'rb' at 0x0A597D30>}
```

I'm using not just `open()` but `codecs.open()` because plain `open()` didn't allow me to send without such errors. The other side gave me _Use HTTP post and provide only a file_.


I don't understand what this means:

> The other side gave me _Use HTTP post and provide only a file._

But I can only assume that you're using the `files` parameter when you should not be using `multipart/form-data` requests, but instead should just be sending the plain data via the `data` parameter. That's not a bug and further difficulties you have should be posed to [StackOverflow](http://stackoverflow.com/questions/tagged/python-requests)