Cogniac / cogniac-sdk-py

Python SDK for Cogniac Public API
Apache License 2.0
5 stars 6 forks source link

python3.5 CogniacConnection - TypeError: the JSON object must be str, not 'bytes' #119

Open CogniacViSean opened 2 years ago

CogniacViSean commented 2 years ago

Customer is trying to use the SDK to upload media, but they get the following error:

They've set COG_USER and COG_PASS environment variables. I cannot seem to duplicate this issue.

user annotations\ $ python3 ./upload_points_xml.py 2022-01-26 13:52:17 INFO Connecting to Cogniac system at https://api.cogniac.io Traceback (most recent call last): File "./upload_points_xml.py", line 207, in cc = cogniac.CogniacConnection(tenant_id=TENANT_ID) File "/home/user/.local/lib/python3.5/site-packages/cogniac/cogniac.py", line 172, in init self.tenant = CogniacTenant.get(self) File "/home/user/.local/lib/python3.5/site-packages/retrying.py", line 49, in wrapped_f return Retrying(*dargs, dkw).call(f, *args, *kw) File "/home/user/.local/lib/python3.5/site-packages/retrying.py", line 206, in call return attempt.get(self._wrap_exception) File "/home/user/.local/lib/python3.5/site-packages/retrying.py", line 247, in get six.reraise(self.value[0], self.value[1], self.value[2]) File "/usr/lib/python3/dist-packages/six.py", line 686, in reraise raise value File "/home/user/.local/lib/python3.5/site-packages/retrying.py", line 200, in call attempt = Attempt(fn(args, kwargs), attempt_number, False) File "/home/user/.local/lib/python3.5/site-packages/cogniac/tenant.py", line 30, in get return CogniacTenant(connection, json.loads(resp.content)) File "/usr/lib/python3.5/json/init.py", line 312, in loads s.class.name)) TypeError: the JSON object must be str, not 'bytes'

spatel-cog commented 2 years ago

This could be a utf-8 decode issue. Can you help the customer modify line 30 in tenant.py to:

return CogniacTenant(connection, json.loads(resp.content.decode('utf-8')))

Similarly line 25 of user.py I can replicate this issue with python 3.5 but not with python 3.9 which handles this differently. Python 3.5 is deprecated. Can they use a version >= 3.7?

CogniacViSean commented 2 years ago

They'll update their version of python, otherwise updating those 2 files has worked in the meantime, thank you!