Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix issue for python 3.5 and lower, json.loads would not accept bytes #359

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion twilio/base/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def process_response(self, response):
if response.status_code != 200:
raise TwilioException('Unable to fetch page', response)

return json.loads(response.content)
return json.loads(response.content.decode('utf-8'))

def load_page(self, payload):
"""
Expand Down
8 changes: 4 additions & 4 deletions twilio/base/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def exception(cls, method, uri, response, message):
"""
# noinspection PyBroadException
try:
error_payload = json.loads(response.content)
error_payload = json.loads(response.content.decode('utf-8'))
if 'message' in error_payload:
message = '{}: {}'.format(message, error_payload['message'])
code = error_payload.get('code', response.status_code)
Expand All @@ -81,7 +81,7 @@ def fetch(self, method, uri, params=None, data=None, headers=None, auth=None, ti
if response.status_code < 200 or response.status_code >= 300:
raise self.exception(method, uri, response, 'Unable to fetch record')

return json.loads(response.content)
return json.loads(response.content.decode('utf-8'))

def update(self, method, uri, params=None, data=None, headers=None, auth=None, timeout=None,
allow_redirects=False):
Expand All @@ -102,7 +102,7 @@ def update(self, method, uri, params=None, data=None, headers=None, auth=None, t
if response.status_code < 200 or response.status_code >= 300:
raise self.exception(method, uri, response, 'Unable to update record')

return json.loads(response.content)
return json.loads(response.content.decode('utf-8'))

def delete(self, method, uri, params=None, data=None, headers=None, auth=None, timeout=None,
allow_redirects=False):
Expand Down Expand Up @@ -208,5 +208,5 @@ def create(self, method, uri, params=None, data=None, headers=None, auth=None, t
if response.status_code < 200 or response.status_code >= 300:
raise self.exception(method, uri, response, 'Unable to create record')

return json.loads(response.content)
return json.loads(response.content.decode('utf-8'))