Skip to content

decoding response content so it can be json loaded in python 3 without simplejson#63

Open
i-yang wants to merge 1 commit intosailthru:masterfrom
chairish:master
Open

decoding response content so it can be json loaded in python 3 without simplejson#63
i-yang wants to merge 1 commit intosailthru:masterfrom
chairish:master

Conversation

@i-yang
Copy link
Copy Markdown

@i-yang i-yang commented Apr 24, 2017

In Python 3, without simplejson, a successful api_post call returns the following exception:
TypeError: the JSON object must be str, not 'bytes'. The reason seems to be that response.content is a bytes literal, which need to be decoded before being passed in to json.loads.

simplejson.loads seems to handle byte literals, but unfortunately, simplejson conflicts with some of the other third party libraries we're using.

vnatakam added a commit that referenced this pull request Apr 17, 2026
…hods

- sailthru_response.py: use response.text instead of response.content so
  simplejson (which rejects bytes) receives a str; also catch TypeError in
  addition to ValueError for robustness
- sailthru_client.py: remove redundant json.loads() in receive_verify_post
  since get_body() already returns a parsed dict
- sailthru_client.py: fix get_signature_string() returning bytes instead of
  str by moving .encode('utf-8') into get_signature_hash() where hashlib needs it
- test: update receive_verify_post mock to return a dict matching real get_body() behavior
- setup.py: bump version to 2.3.6

Closes INT-1681. Resolves the same issue identified in PR #63 (open since 2017).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant