matrix-org / matrix-org/matrix-python-sdk

JSONDecodeError when trying to logging with username and password

Open
#288 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Api layer bug question
Dominant language
Python
Stars
266
Forks
118
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the login call from matrix_client/client.py and trace the request handling in matrix_client/api.py, especially _send and login. Inspect the server response before JSON parsing and compare it with the expected login response; done means identifying the cause of the empty or non-JSON response and documenting a confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.