kennethreitz/requests — Issue #459: Unicode cookie key values fail in translate
Author: mlakewood
Created: 2012-02-27 01:34:21+00:00
State: open

Hi,

the following code

import requests

cookie = {u'test_cookie': 'foobar'}
res = requests.get('http://httpbin.org/cookies', cookies=cookie)
print res.cookies

thows the following error

```Python
File "requests_translate_bug.py", line 5, in
res = requests.get('http://httpbin.org/cookies', cookies=cookie)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/api.py", line 51, in get
return request('get', url, **kwargs)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/api.py", line 39, in request
return s.request(method=method, url=url, **kwargs)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/sessions.py", line 200, in request
r.send(prefetch=prefetch)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/models.py", line 507, in send
c[k] = v
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/packages/oreos/monkeys.py", line 604, in __setitem__
self.__set(key, rval, cval)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/packages/oreos/monkeys.py", line 597, in __set
M.set(key, real_value, coded_value)
File "/home/markl/Envs/req-bug/lib/python2.6/site-packages/requests/packages/oreos/monkeys.py", line 470, in set
if "" != translate(key, idmap, LegalChars):
File "/usr/lib/python2.6/string.py", line 493, in translate
return s.translate(table, deletions)
TypeError: translate() takes exactly one argument (2 given)

````

If the key in the cookies dictionary isnt a unicode character then this doesnt happen.

(req-bug)markl@markl-desktop:~/dev/requests-bug$ pip freeze
certifi==0.0.8
chardet==1.0.1
requests==0.10.6
wsgiref==0.1.2
(req-bug)markl@markl-desktop:~/dev/requests-bug$

Hope it helps.

Cheers

Mark