Skip to content

Instantly share code, notes, and snippets.

@jessegonzalez
Created February 3, 2012 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessegonzalez/1727080 to your computer and use it in GitHub Desktop.
Save jessegonzalez/1727080 to your computer and use it in GitHub Desktop.
request issue with unicode?
#!/usr/bin/env python
from requests import get
def func(endpoint, dictionary):
resp = get(endpoint, headers=dictionary)
print(resp.status_code)
if __name__ == "__main__":
my_unicode_dict = {u'foo': u'bar'}
my_other_dict = {'foo': 'bar'}
func("http://www.google.com", my_other_dict)
func("http://www.google.com", my_unicode_dict)
$ python test.py
200
Traceback (most recent call last):
File "test.py", line 15, in <module>
func("http://www.google.com", my_unicode_dict)
File "test.py", line 7, in func
resp = get(endpoint, headers=dictionary)
File "/Users/jesse.gonzalez/Envs/authmonitor/lib/python2.7/site-packages/requests/api.py", line 51, in get
return request('get', url, **kwargs)
File "/Users/jesse.gonzalez/Envs/authmonitor/lib/python2.7/site-packages/requests/api.py", line 39, in request
return s.request(method=method, url=url, **kwargs)
File "/Users/jesse.gonzalez/Envs/authmonitor/lib/python2.7/site-packages/requests/sessions.py", line 159, in request
headers[k] = header_expand(v)
File "/Users/jesse.gonzalez/Envs/authmonitor/lib/python2.7/site-packages/requests/utils.py", line 152, in header_expand
for i, (value, params) in enumerate(headers):
ValueError: need more than 1 value to unpack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment