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

JSONDecodeError when trying to logging with username and password #288

Open
MyDev45 opened this issue Nov 29, 2018 · 2 comments
Open

JSONDecodeError when trying to logging with username and password #288

MyDev45 opened this issue Nov 29, 2018 · 2 comments

Comments

@MyDev45
Copy link

MyDev45 commented Nov 29, 2018

Hi there!
I'm currently trying to use Matrix to log in a server webpage with username and password. I'm using Python 3 and the appropriate SDK, but I'm facing an issue: Since it looks that I succeed in reaching the server page address, an error occurs when it comes to logging in:

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    token = client.login(username="***", password="***", limit=10, sync=True, device_id=None)
  File "/usr/local/lib/python3.6/dist-packages/matrix_client-0.4.0.dev0-py3.6.egg/matrix_client/client.py", line 278, in login
  File "/usr/local/lib/python3.6/dist-packages/matrix_client-0.4.0.dev0-py3.6.egg/matrix_client/api.py", line 181, in login
  File "/usr/local/lib/python3.6/dist-packages/matrix_client-0.4.0.dev0-py3.6.egg/matrix_client/api.py", line 761, in _send
  File "/home/user/.local/lib/python3.6/site-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

My code is really basic:

#!/usr/bin/env python3
from matrix_client.client import MatrixClient
client = MatrixClient("webpage_logging_address")
token = client.login(username="***", password="***", limit=10, sync=True, device_id=None)

I've been searching for a solution for hours, without success. Any idea of why this happens and how to solve the problem?

Thanks a lot,

MyDev

@non-Jedi
Copy link
Collaborator

non-Jedi commented Jan 9, 2019

Could you please show the exact value you're using in your code where you currently have "webpage_logging_address"? Also, please list which commit you're using since it appears you aren't using a released version of the library.

@non-Jedi
Copy link
Collaborator

non-Jedi commented Jan 9, 2019

Without knowing what version you're using, I can't track the error very precisely, but I'm guessing you're receiving invalid JSON from the server, and the error is coming from this line:

return response.json()

Regardless of what's causing the underlying issue, we should have error handling there for the situation where invalid JSON is returned. This would also make troubleshooting issues like this significantly easier.

@non-Jedi non-Jedi added the bug label Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants