metabase_api_python: authentication triggers an error simplejson.errors.JSONDecodeError

I installed the package and I tried to authenticate with both the command line and a script, yet it’s not working. When I run this code

from metabase_api import Metabase_API

Metabase_API("http://localhost:4009/","test@test.com","test123")

I’m getting the following error in the my terminal

Traceback (most recent call last):
  File "mbmap.py", line 59, in <module>
    Metabase_API("http://localhost:4009/","test@test.com","test123")
  File "/home/test/.local/lib/python3.8/site-packages/metabase_api/metabase_api.py", line 13, in __init__
    self.authenticate()
  File "/home/test/.local/lib/python3.8/site-packages/metabase_api/metabase_api.py", line 25, in authenticate
    self.session_id = res.json()['id']
  File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

I had same issue and it was exactly what @aattpcfish pointed, removal of last / solved it. Perhaps you may use os.path.join(self.domain, 'api', 'session') instead of self.domain + '/api/session'

It might be the domain . input http://localhost:4009/ res = requests.post(self.domain + '/api/session', json = conn_header)

and call http://localhost:4009//api/session lead to the result with r'', which status code is still 200.

@vvaezian I just got this same issue (first time trying to use the package).

The printout from your test code gives me:

200

Note res.text is an empty string. print(type(res.text)) returns <class 'str'>

EDIT: Just remembered, I’m on version v0.35.4 Maybe an upgrade needed?