Trying to understand errors from import_logs.py

Matomo version: 5.14.0

First time setting up import_logs.py, and running via cron . Compared to the polish and refinement of the online side, the script side is very basic!

I’m getting the errors shown below while running import_logs.py. I turned debug on, but still it’s not clear what the issue is.

2026-09-28 16:54:01,926: [DEBUG] Accepted hostnames: all
2026-09-28 16:54:01,926: [DEBUG] Matomo Tracker API URL is: https://[redacted]/matomo/index.php
2026-09-28 16:54:01,927: [DEBUG] Matomo Analytics API URL is: https://[redacted]/matomo/index.php
2026-09-28 16:54:01,927: [DEBUG] Authentication token token_auth is: [redacted]
2026-09-28 16:54:01,927: [DEBUG] Resolver: static
2026-09-28 16:54:02,654: [DEBUG] Request redirected (code: 302) to 'https://[redacted]/matomo/index.php'
Traceback (most recent call last):
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1884, in _call_api
    return json.loads(res)
  File "/usr/lib64/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 2986, in <module>
    resolver = config.get_resolver()
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1427, in get_resolver
    return StaticResolver(self.options.site_id)
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1959, in __init__
    site = matomo.call_api(
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1943, in call_api
    return self._call_wrapper(self._call_api, None, None, method, **kwargs)
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1895, in _call_wrapper
    response = func(*args, **kwargs)
  File "/[redacted]/matomo/misc/log-analytics/import_logs.py", line 1886, in _call_api
    raise urllib.error.URLError('Matomo returned an invalid response: ' + res.decode("utf-8") )
AttributeError: 'str' object has no attribute 'decode

My invocation looked like this:

python3 /[redacted]/matomo/misc/log-analytics/import_logs.py \
     --url=https://[redacted]/matomo/index.php \
     --idsite=1 \
     --debug \
     --auth-config=/[redacted]matomo_auth.cfg \
     /[redacted]/[log file]

The 302 redirect in your debug log is the real clue here: the API request is being redirected to the Matomo index page, which returns HTML instead of JSON, and that is why json parsing fails with ‘Expecting value’. This usually means the request is landing on a login page - most often an invalid or expired token_auth in your auth config file, so I would check that token by logging into Matomo with it and regenerating it if needed. Also confirm that the --url value does not cause an extra redirect, for example an http to https redirect or a missing trailing slash, since import_logs.py does not handle those well. The AttributeError about ‘str’ having no attribute ‘decode’ at the end is just a bug in the script’s own error reporting that hides the real server response, so ignore that part and focus on the 302. One more thing: --url should point to your Matomo base URL; if you are passing index.php directly, try the plain base URL instead and see whether the redirect disappears.

The traceback suggests that the API response cannot be parsed as JSON, followed by a second error when the error handler calls .decode() on a string.

Could you check the response status, Content-Type, and a short redacted snippet of the response body after the 302 redirect? That should help identify whether an HTML page or an empty response is being returned instead of JSON. Please remove authentication tokens before sharing any output.

Thank you for your help - the issue is that the script was pointing to matomo/index.php and not to matomo/