-
Notifications
You must be signed in to change notification settings - Fork 431
Avoid converting to bytes the Python 3 str header values #104
Conversation
can you paste a traceback for the |
@craigcitro I'm suffered same error. File "google.py", line 93, in get_email
(resp, content) = http.request("https://www.googleapis.com/oauth2/v2/userinfo")
File "/venv/lib/python3.4/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/venv/lib/python3.4/site-packages/oauth2client/client.py", line 547, in new_request
redirections, connection_type)
File "/venv/lib/python3.4/site-packages/httplib2/__init__.py", line 1139, in request
headers = self._normalize_headers(headers)
File "/venv/lib/python3.4/site-packages/httplib2/__init__.py", line 1107, in _normalize_headers
return _normalize_headers(headers)
File "/venv/lib/python3.4/site-packages/httplib2/__init__.py", line 195, in _normalize_headers
return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.items()])
File "/venv/lib/python3.4/site-packages/httplib2/__init__.py", line 195, in <listcomp>
return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.items()])
TypeError: sequence item 0: expected str instance, bytes found |
Finally got it ! I wasn't able to understand why for a while, then it hit me. So the unit test never test the behavior inherited from the actual Now that the problem is identified I can work on a fix. Cheers |
I first restore your original code, then patch the |
The only fix I'm thinking for now, is to fix the httplib2 project. def _normalize_headers(headers):
return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.items()]) with def _normalize_headers(headers):
normalized_headers = {}
for key, value in headers.items():
if isinstance(value, bytes):
value = value.decode('utf8')
value = NORMALIZE_SPACE.sub(value, ' ').strip()
value = value.encode('utf8')
else:
value = NORMALIZE_SPACE.sub(value, ' ').strip()
normalized_headers[key.lower()] = value
return normalized_headers If you have another suggestion @craigcitro, don't hesitate to stop me. |
@dulaccc: if the best way to solve the problem you've described here is with a change to httplib2, we'd like to exhaust that possibility before looking further at this pull request changing oauth2client. @jcgregorio has asked for unit test coverage in jcgregorio/httplib2#291 so it looks like that's the way to move all this forward? |
Please reassess this pull request now that jcgregorio/httplib2#291 has been accepted? |
Friendly ping - what work remains to be done here? |
Also, please correct me if I'm wrong, but it looks like you haven't yet signed Google's Contributor License Agreement. You must do so before we can accept your contribution. |
@nathanielmanistaatgoogle This can be closed. These issues were address upstream in jcgregorio/httplib2#291 and jcgregorio/httplib2#296 |
I thought so, but was leaving it open on the off chance that there was something we might want to do here with respect to httplib2 not yet having cut a new release. The more I think about it, the more that's a problem outside the scope of this pull request. |
the method
clean_headers
was turning python 3 str instances into bytes, which was causing the httplib2 module to raise an exception.Cheers