Keep getting JSONDecode error
Closed this issue · 9 comments
Hi,
The following error keeps showing up (v1.2.0), possibly some unhandled error response from the API?
[07/19/22 23:28:50] INFO Will challenge xxxbot for a standard game. matchmaking.py:77
Traceback (most recent call last):
File "/root/lichess-bot/venv/lib/python3.9/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/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 "/root/lichess-bot/lichess-bot.py", line 794, in <module>
start(li, user_profile, CONFIG, logging_level, args.logfile)
File "/root/lichess-bot/lichess-bot.py", line 245, in start
matchmaker.challenge()
File "/root/lichess-bot/matchmaking.py", line 78, in challenge
challenge_id = self.create_challenge(bot_username, base_time, increment, days, variant) if bot_username else None
File "/root/lichess-bot/matchmaking.py", line 41, in create_challenge
challenge_id = self.li.challenge(username, params).get("challenge", {}).get("id")
File "/root/lichess-bot/lichess.py", line 134, in challenge
return self.api_post(ENDPOINTS["challenge"].format(username), payload=params, raise_for_status=False)
File "/root/lichess-bot/venv/lib/python3.9/site-packages/backoff/_sync.py", line 105, in retry
ret = target(*args, **kwargs)
File "/root/lichess-bot/lichess.py", line 74, in api_post
return response.json()
File "/root/lichess-bot/venv/lib/python3.9/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Thanks
Can you run lichess-bot with -v and -l (python lichess-bot.py -v -l logs.txt
) and upload the logs.txt file here?
Also post the matchmaking section of your config.yml. For example:
matchmaking:
allow_matchmaking: true # Set it to 'true' to challenge other bots.
challenge_variant: "random" # If set to 'random', the bot will choose one variant from the variants enabled in 'challenge.variants'.
challenge_timeout: 1 # Create a challenge after being idle for 'challenge_timeout' minutes.
challenge_initial_time: 60 # Initial time in seconds of the challenge.
challenge_increment: 3 # Increment in seconds of the challenge.
# challenge_days: 2 # Days for correspondence challenge. If this option is enabled, a correspondence challenge will be created even if 'challenge_initial_time' is enabled.
opponent_min_rating: 600 # Opponents rating should be above this value (600 is the minimum rating in lichess).
opponent_max_rating: 4000 # Opponents rating should be below this value (4000 is the maximum rating in lichess).
challenge_mode: "casual" # Set it to the mode in which challenges are sent. Possible options are 'casual', 'rated' and 'random'.
@TheYoBots I played 11 0.5+0
games with challenge timeout = 0.0001
and I couldn't reproduce this. According to redsalmon91 the error happens often, so it doens't make sense why my bot wouldn't get this but their bot gets this error very often. Do you also get this error?
Hi, sorry for the late reply. The error response from API is 429 too many requests. I was doing 1m + 1s bullet games, and the rate_limit setting was 0ms.
I have the same error after switching to a different host (with different IP) and with a new token.
Thanks.
@TheYoBots I played 11
0.5+0
games withchallenge timeout = 0.0001
and I couldn't reproduce this. According to redsalmon91 the error happens often, so it doens't make sense why my bot wouldn't get this but their bot gets this error very often. Do you also get this error?
Since your PR (matchmaking) has been merged I haven't updated lichess-bot and never faced this error until day before yesterday. I think it's because some lichess rate limits would have been hit, though I'd expect that to be rare.
@redsalmon91 Can you test with #503 if you still get this error?
@redsalmon91 Can you test with #503 if you still get this error?
I have tried to increase the matchmaking time, seem to solve the problem. Thank you.
Also, I do not want to mislead you, but I think this can also be related to me opening multiple clients to watch the live games at the same time (phone, browser for TV projection etc.)
I've started getting the same errors as @redsalmon91. I started getting the errors this morning and haven't been able to challenge another bot since. This could be because I'm playing through a VPN (I don't know if lichess is accessible where I am without it) and the server my bot is playing through is blocked due to the sum of all other bots playing through it.
I think the JSON error is a result of an empty string being returned from the challenge API call.
My matchmaking config (note the 2 minutes challenge_timeout
):
matchmaking:
allow_matchmaking: true # Set it to 'true' to challenge other bot in a set interval, time control and range.
challenge_timeout: 2 # Interval in minutes between two challenges.
challenge_initial_time: 120 # Initial time in seconds of the challenge.
challenge_increment: 0 # Increment in seconds of the challenge.
# challenge_days: 2 # Days for correspondence challenge. If this option is enabled, a correspondence challenge will be created even if 'challenge_initial_time' is enabled.
opponent_min_rating: 0 # Opponents rating should be above this value
opponent_max_rating: 5000 # Opponents rating should be below this value
challenge_mode: "rated" # Set it to the mode in which challenges are sent. Possible options are 'casual', 'rated' and 'random'.
The errors (I've added some extra logging):
2022-07-27 10:08:24,945 __main__ ERROR Expecting value: line 1 column 1 (char 0)
2022-07-27 10:08:24,950 __main__ ERROR Traceback (most recent call last):
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\.venv\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Program Files\Python310\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Program Files\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\Python310\lib\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 "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\lichess-bot.py", line 816, in <module>
start(li, user_profile, CONFIG, logging_level, args.logfile)
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\lichess-bot.py", line 250, in start
matchmaker.challenge()
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\matchmaking.py", line 78, in challenge
challenge_id = self.create_challenge(bot_username, base_time, increment, days, variant) if bot_username else None
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\matchmaking.py", line 41, in create_challenge
challenge_id = self.li.challenge(username, params).get("challenge", {}).get("id")
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\lichess.py", line 134, in challenge
return self.api_post(ENDPOINTS["challenge"].format(username), payload=params, raise_for_status=False)
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\.venv\lib\site-packages\backoff\_sync.py", line 105, in retry
ret = target(*args, **kwargs)
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\lichess.py", line 74, in api_post
return response.json()
File "C:\Users\Mark Harrison\Documents\GitHub\lichess-bot\.venv\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Sometimes, the errors include ReadTimeoutErrors
when I added JSONDecodeError
to the backoff
parameters:
2022-07-27 09:39:17,562 matchmaking INFO Will challenge chesssevigcom for a standard game.
2022-07-27 09:39:17,888 urllib3.connectionpool DEBUG https://lichess.org:443 "POST /api/challenge/chesssevigcom HTTP/1.1" 429 35
2022-07-27 09:39:17,897 backoff DEBUG Backing off api_post(...) for 0.0s (requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0))
... skip repetitions ...
2022-07-27 09:39:27,751 urllib3.connectionpool DEBUG Starting new HTTPS connection (2): lichess.org:443
2022-07-27 09:39:29,975 backoff DEBUG Backing off api_post(...) for 0.0s (requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='lichess.org', port=443): Read timed out. (read timeout=2))
Half a day later and everything seems to be working fine. Maybe this was a temporary hiccup. Anyway, closing again.