question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unterminated string starting at

See original GitHub issue

Im getting a strange error. Im currently using seedcross and get this error with your API. Im unsure of why.

here is the traceback.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/qbittorrentapi/decorators.py", line 161, in wrapper
    result = response.json()
  File "/root/.local/lib/python3.8/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 239700 (char 239699)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.local/lib/python3.8/site-packages/background_task/tasks.py", line 43, in bg_runner
    func(*args, **kwargs)
  File "/root/seedcross/crseed/tasks.py", line 80, in backgroundCrossSeedTask
    iterTorrents(dlclient, param, log)
  File "/root/seedcross/crseed/CrossSeedAutoDL.py", line 356, in iterTorrents
    torList = dlclient.loadTorrents()
  File "/root/seedcross/crseed/torclient.py", line 196, in loadTorrents
    torList = self.qbClient.torrents_info()
  File "/usr/local/lib/python3.8/site-packages/qbittorrentapi/decorators.py", line 112, in wrapper
    return func(client, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/qbittorrentapi/decorators.py", line 170, in wrapper
    raise APIError("Exception during response parsing. Error: %r" % exc)
qbittorrentapi.exceptions.APIError: Exception during response parsing. Error: JSONDecodeError('Unterminated string starting at: line 1 column 239700 (char 239699)')

Any idea what the cause could be?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
swannie-eirecommented, Mar 4, 2022

so i had that script running for over 24 hours and have not seen the issue once.

I also have not replicated the issue with seedcross. I have a feeling that the issue is that when i first run seedcross it overloads the qbittorrent instances as so many new torrents are being added and being rechecked and thats the cause of the Unterminated string since the qbit is so overloaded.

i think its best to close this for now and Ill reopen if i can re-produce.

BTW thanks for the prompt responses and the excellent help.

1reaction
rmartin16commented, Mar 2, 2022

hmm…interesting. That suggests the problem is likely intermittent…and as such makes it much harder to track down. Additionally, the dictionary for each torrent that is returned from client.torrents_info() do not contain much dynamic content other than changing statistics; so, that does make me wonder if special characters could really be the root cause given I wouldn’t expect them to be appearing and disappearing in this payload…

Nonetheless, another option is just to run client.torrents_info() in an infinite loop:

from time import sleep
import logging
import qbittorrentapi

logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] {%(name)s:%(lineno)d} %(levelname)s - %(message)s')
client = qbittorrentapi.Client(host='localhost:8080', username='admin', password='adminadmin', VERBOSE_RESPONSE_LOGGING=True)
LOOP_INTERVAL = 3  # seconds

while True:
    for idx in range(len(client.sync.maindata()['torrents'])):
        print(client.torrents_info(limit=1, offset=idx))
    sleep(LOOP_INTERVAL)

You can change LOOP_INTERVAL to have it run as often as you like. And the loops will break out as soon as there’s a problem; so, no need to watch it. The exception will be the last thing printed once one occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python & JSON: ValueError: Unterminated string starting at
Python says there is in an unterminated string so I looked at the end of the JSON in the file that fails and...
Read more >
Unterminated string starting at: line 1 column 127395 (char ...
Uploading the test add-on (attached), I get the following traceback on validation: "Traceback (most recent call last): File ...
Read more >
json.decoder.JSONDecodeError: Unterminated string ... - GitHub
I am using gunicorn + Flask + Docker with async gevent workers. My application receives a request with a json body that contains...
Read more >
Incorrect position reported in JSONDecodeError when loading ...
When loading an invalid json that ends in an unterminated string that ... JSONDecodeError: Unterminated string starting at: line 1 column 1 ...
Read more >
How to fix an unterminated string literal in Python - Quora
Unterminated string constant means that you are missing the ending quotes of string. Just put the ending quotes and it's done .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found