kennethreitz/requests — pull request #884 by everbird (2012-10-08 09:21:19+00:00)
Title: Support CJK parameters when post files

When I post files with CJK parameters I got this exception:

Traceback (most recent call last):
File "/home/everbird/code/requests/tests/test_requests.py", line 358, in test_POSTBIN_GET_POST_FILES_WITH_CJK_PARAMS
data={'some': '中文'})
File "/home/everbird/code/requests/requests/api.py", line 98, in post
return request('post', url, data=data, **kwargs)
File "/home/everbird/code/requests/requests/safe_mode.py", line 39, in wrapped
return function(method, url, **kwargs)
File "/home/everbird/code/requests/requests/api.py", line 51, in request
return session.request(method=method, url=url, **kwargs)
File "/home/everbird/code/requests/requests/sessions.py", line 241, in request
r.send(prefetch=prefetch)
File "/home/everbird/code/requests/requests/models.py", line 529, in send
(body, content_type) = self._encode_files(self.files)
File "/home/everbird/code/requests/requests/models.py", line 365, in _encode_files
new_fields.append((field, str(val)))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

For py2, `str` is actually `unicode` according to `requests/compat.py`. It is OK like this:
```python
In [1]: str('a')
Out[1]: 'a'

In [2]: unicode('a')
Out[2]: u'a'
```
but it failed as below:
```python
In [3]: str('中文')
Out[3]: '\xe4\xb8\xad\xe6\x96\x87'

In [4]: unicode('中文')
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
in ()
----> 1 unicode('中文')

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
```
In `requests/models.py` at line 363-365 the `str()` seems should be the builtin `str`, not `unicode`. So I wrote a test named `test_POSTBIN_GET_POST_FILES_WITH_CJK_PARAMS` and fixed it.

Hope it helps.