rhgrant10 / berserk

Python client for the lichess API
https://berserk.readthedocs.io
Other
142 stars 36 forks source link

error on fresh install with simplejson #16

Open vshesh opened 4 years ago

vshesh commented 4 years ago

Description

installed berserk a few minutes ago

Describe what you were trying to get done.

import berserk
client = berserk.Client(berserk.SessionToken('...'))
client.account.get()

Tell us what happened, what went wrong, and what you expected to happen.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
    client.account.get()
  File "/usr/local/lib/python3.8/site-packages/berserk/clients.py", line 115, in get
    return self._r.get(path, converter=models.Account.convert)
  File "/usr/local/lib/python3.8/site-packages/berserk/session.py", line 60, in get
    return self.request('GET', *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/berserk/session.py", line 56, in request
    return fmt.handle(response, is_stream=is_stream, converter=converter)
  File "/usr/local/lib/python3.8/site-packages/berserk/formats.py", line 35, in handle
    return converter(self.parse(response))
  File "/usr/local/lib/python3.8/site-packages/berserk/formats.py", line 76, in parse
    return response.json(cls=self.decoder)
  File "/usr/local/lib/python3.8/site-packages/requests/models.py", line 889, in json
    return complexjson.loads(
  File "/usr/local/lib/python3.8/site-packages/simplejson/__init__.py", line 542, in loads
TypeError: __init__() got an unexpected keyword argument 'encoding'

error is happening somewhere deep in the simplejson code. uninstalling simplejson makes the function work, but I shouldn't need to do this - I use simplejson in many other places (and other libraries depend on it) and so this is a bug for me. I tried to debug it myself for a but but could not understand why this error was appearing - the parameters look fine.

vshesh commented 4 years ago

Ok, looks like this is some kind of known issue that requires a monkeypatch in the user libraries, since requests library is not solving the problem... https://github.com/psf/requests/issues/4842

9acca9 commented 4 years ago

Oh, i think that my problem is the same: https://github.com/rhgrant10/berserk/issues/17

"this is some kind of known issue that requires a monkeypatch in the user libraries". What is the meaning of this? (i dont speak english)

Thanks.

@vshesh so, you could fix this?

vshesh commented 4 years ago

The real issue is with the requests library, so the way I fixed it is I got rid of the simplejson import within that library. I'm not sure how familiar with python you are.... the way to do this is to go to the requests library package folder and change the code there. There's a compat file that exports a variable json - i replaced that code with import json instead.

this is not a good solution, actually, it's a terrible one. But it works and it solves the problem at the source rather than requiring a lot of upstream changes.

9acca9 commented 4 years ago

@vshesh Oh... i uninstall SimpleJson.... im gonna look for what you say. about "how familiar with python"... prebeginner.

Thanks for your work.

PinyaColada commented 3 years ago

I have the same problem, it will be fixed soon? changing the code of your copy of the library is terrible and not a practical solution

mattrussell2 commented 2 years ago

My solution was to remove encoding=encoding from line 535 in __init__.py of the simplejson package...yuck