odd code in requests() regarding json decoding #302
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#302
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Here is the code (with unrelated stuff left out):
response is a requests.Response object. response.content is of type str in Python 2.7 and of type bytes in Python 3.
response.content.decode('utf-8')will return a string regardless of Python version socontentis now a string. string does not have an attribute of json so that will always raise an exception.Now the response object has a json method that guesses the encoding and then decodes the json. It looks like this bug was introduced in this commit: [
abaa3e558a] and then was worked around but not fixed in this commit: [6a3539882c].Related to this is the decoding of content that came about because of this ticket: #43. I believe requests now handles this so the decoding can be dropped and response.content.json() can be used.