Skip to content
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

JSON loads encoding error #15

Closed
AnonJohn opened this issue May 20, 2023 · 6 comments
Closed

JSON loads encoding error #15

AnonJohn opened this issue May 20, 2023 · 6 comments

Comments

@AnonJohn
Copy link

Hi - I'm getting this error: TypeError: JSONDecoder.init() got an unexpected keyword argument 'encoding'

For instance: A call to "client.users.get_public_data(u'veysey')" has this traceback below.

I think this stems from the change in Python 3.9 in which the keyword encoding was removed from json.loads

Any advice would be appreciated!

File "/home/veysey/.local/lib/python3.10/site-packages/berserk/clients.py", line 229, in get_public_data
return self._r.get(path, converter=models.User.convert)
File "/home/veysey/.local/lib/python3.10/site-packages/berserk/session.py", line 177, in get
return self.request(
File "/home/veysey/.local/lib/python3.10/site-packages/berserk/session.py", line 102, in request
return fmt.handle(response, is_stream=stream, converter=converter)
File "/home/veysey/.local/lib/python3.10/site-packages/berserk/formats.py", line 44, in handle
return converter(self.parse(response))
File "/home/veysey/.local/lib/python3.10/site-packages/berserk/formats.py", line 87, in parse
return response.json(cls=self.decoder)
File "/home/veysey/.local/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/home/veysey/.local/lib/python3.10/site-packages/simplejson/init.py", line 533, in loads
return cls(encoding=encoding, **kw).decode(s)
TypeError: JSONDecoder.init() got an unexpected keyword argument 'encoding'

@AnonJohn
Copy link
Author

I think this is derivative of a known issue with requests and a multi-year argument over there over whether to default to simplejson or json. Doesn't look like a berzerk issue per se.

psf/requests#4842

@AnonJohn
Copy link
Author

Discussion of addressing it by catching the error and retrying it in this berserk fork: rhgrant10/berserk#17

@AnonJohn
Copy link
Author

The change merged in that fork fixes my issue. Not sure if creates other problems.
ZackClements/berserk@a33272c

@AnonJohn
Copy link
Author

To recap this "issue". There is a dispute among requests package maintainers. They use simplejson, which is no longer compatible with the python json library (one has the encoding parameter for "loads", one doesn't). requests maintainers appear unwilling to check for compatibility.

I have simplejson installed; requests uses that preferentially. The ideal solution would be for simplejson and json to require the same arguments. Probably will happen eventually. In the interim requests should test for the library; they have been asked and appear unwilling to fix it.

Thus all upstream users need to test. Options for berserk:

  1. Ignore it as an edge case (people impacted can find this thread and make the above fix
  2. Consider the patch linked to in the predecessor / pre-fork beserk versions.

Cheers!

@kraktus
Copy link
Member

kraktus commented May 21, 2023

Thanks for the report, not sure exactly how to fix at the moment but

The change merged in that fork fixes my issue. Not sure if creates other problems.
ZackClements/berserk@a33272c

Is indeed breaking and was quickly reverted afterwards: ZackClements/berserk#5

@AnonJohn
Copy link
Author

Thanks for the reply. I suggest you simply close the bug; at some point simplejson or requests will surely fix it. Cheers!

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

No branches or pull requests

2 participants