Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Must decode json in python 3 . Assume default utf8 encoding. #36

Merged
merged 1 commit into from
Jun 6, 2014

Conversation

itd
Copy link
Contributor

@itd itd commented Jun 5, 2014

This fixes an error I was getting in Python 3.4:

*** TypeError: the JSON object must be str, not 'bytes'

By decoding the json returned, seems to fix the issue:

-> return json.loads(response.content)
(Pdb) response.content
b'[{"name":"p_nodes_avail","columns":["time","sequence_number","active"],"points":[[1402002269,100001,1391],[1402001816,90001,1391],[1402001338,80001,1391],[1402000896,70001,1391],[1402000386,60001,1391],[1402000364,50001,1391]]}]'
(Pdb) json.loads(response.content)
*** TypeError: the JSON object must be str, not 'bytes'
(Pdb) json.loads(response.content.decode('utf8'))
[{'points': [[1402002269, 100001, 1391], [1402001816, 90001, 1391], [1402001338, 80001, 1391], [1402000896, 70001, 1391], [1402000386, 60001, 1391], [1402000364, 50001, 1391]], 'columns': ['time', 'sequence_number', 'active'], 'name': 'p_nodes_avail'}]

Let me know if this works for you.

Thanks!
Kurt

@toddboom
Copy link
Contributor

toddboom commented Jun 6, 2014

@itd Looks good, thanks!

toddboom added a commit that referenced this pull request Jun 6, 2014
Must decode json in python 3 . Assume default utf8 encoding.
@toddboom toddboom merged commit e259392 into influxdata:master Jun 6, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants