-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unicode issues in HttpError and BatchHttpRequest #77
Fix unicode issues in HttpError and BatchHttpRequest #77
Conversation
(1) Squash commits? |
@@ -44,9 +44,9 @@ def _get_reason(self): | |||
"""Calculate the reason for the error from the response content.""" | |||
reason = self.resp.reason | |||
try: | |||
data = json.loads(self.content) | |||
data = json.loads(self.content.decode('utf-8')) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@@ -1252,11 +1252,10 @@ def _execute(self, http, order, requests): | |||
if resp.status >= 300: | |||
raise HttpError(resp, content, uri=self._batch_uri) | |||
|
|||
# Now break out the individual responses and store each one. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There are 3 ways that you have for getting to the decode/encode calls:
Personally, I like "It's better to ask forgiveness than permission", so I would go with number 1. I'm not sure if @nathanielmanistaatgoogle has a preference. |
bd7641a
to
226cf7b
Compare
Done
Done, bug I'm not a good English writer.
There were bugs remained relating BatchHttpRequest. I've fixed it. |
@@ -1257,6 +1257,8 @@ def _execute(self, http, order, requests): | |||
|
|||
# Prepend with a content-type header so FeedParser can handle it. | |||
header = 'content-type: %s\r\n\r\n' % resp['content-type'] | |||
if not six.PY2: | |||
content = content.decode('utf-8') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
9852b26
to
e463e5e
Compare
@@ -37,6 +37,9 @@ class HttpError(Error): | |||
@util.positional(3) | |||
def __init__(self, resp, content, uri=None): | |||
self.resp = resp | |||
if not isinstance(content, bytes): | |||
# When see this exception in test, testdata may be wrong |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
1) HttpError parses http response by json.loads. It accepts only unicode on PY3 while response is bytes. So decode response first. 2) BatchHttpRequest uses email.parser.FeedParser. It accepts only unicode on PY3, too. So encode parsed response to emulate normal http response.
LGTM. |
Fix unicode issues in HttpError and BatchHttpRequest
Thanks for the contribution. :-) |
HttpError parses http response by json.loads. It accepts only
unicode on PY3 while response is bytes. So decode response first.
BatchHttpRequest uses email.parser.FeedParser. It accepts only
unicode on PY3, too. So encode parsed response to emulate normal
http response.