#API requests timing out

20 messages · Page 1 of 1 (latest)

autumn trellis
#

I help out some Twitch streamers with commands for their chatbots to get information about players' ratings, arenas, etc. As had been recommended to me by someone a few years ago, I host some Python scripts on Google Cloud Functions, so that the bot command calls my script, the script queries the Lichess API, parses the information, and then passes the result as plain text back to the bot to display in chat.

This has been working fine for quite some time, but recently I've noticed the commands are often timing out in Google Cloud Functions (i.e. taking longer than 1 minute), which is in turn causing the bot to throw an error. Since I haven't encountered the same issue when using the same functions to call the chesscom API instead, I don't think the problem is with the chat bot or the Google Cloud Functions.

This has mostly been happening with my arena command, which gives information about a team's current arenas: it uses the /api/team/{teamID}/arena endpoint to find the tournament IDs, and then the /api/tournament/{tournamentID} endpoints to retrieve information about a specific tournament. However, the timeouts have also occasionally appeared when using a rating command to look up ratings, which uses the /api/user/{username} endpoint, and with a head-to-head command, which calls /api/crosstable/{player1}/{player2}.

These commands all used to work smoothly, but I've noticed these timeouts occurring in the past month or so - I'm afraid I don't remember exactly when they started. I haven't changed anything in my script, so I was wondering if anyone has any idea what might be causing them, and how I could fix them? Thanks in advance!

elder iris
#

hi, thanks, I'm looking into these endpoints

#

so you got timeouts from the /api/team/{teamID}/arena endpoint? do you have a teamID example? I need to reproduce the bug first

autumn trellis
#

Thanks! The teamID used most of the time is the-excellencies

crisp adder
elder iris
#

curl https://lichess.org/api/team/the-excellencies/arena successfully gave me 100 tournaments in about 5 seconds

#

do you set a max query parameter?

autumn trellis
#

Hm, I don't currently - I stream the request and go line-by-line until reaching the first completed arena

elder iris
#

ah, so you call /api/tournament/{tournamentID} while streaming /api/team/the-excellencies/arena

#

can you maybe just post your code

autumn trellis
#

sure, this is the main snippet of the code:

    nextArena = None
    currentArena = None
    lastArena = None
    for line in arenas.iter_lines():
        if line:
            arena = json.loads(line.decode('utf-8'))
            if 'status' in arena.keys():
                status = arena['status']
            else:
                status = 30
            if status == 10:
                nextArena = arena
            elif status == 20:
                currentArena = arena
            else:
                lastArena = arena
                break```
#

It then checks whether the user was asking about the next, current, or previous tournament, and calls /api/tournament/{tournamentID} for that individual tournament

elder iris
#

that looks good, and this times out?

#
curl https://lichess.org/api/team/the-excellencies/arena | wc -l
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  331k    0  331k    0     0  67814      0 --:--:--  0:00:05 --:--:-- 71448
100

works every time for me

autumn trellis
#

It has been sometimes, not always. I'll try debugging a bit more to see if the timing out is occurring later in the script.

#

but thanks for looking into it! I guess that means the problem is somewhere else in the pipeline, but I'm a bit at a loss as to where it could be, since I haven't changed anything in the script recently

bronze locust
#

Are you able to find out when exactly the problem started?
For me and liflitz, timeout problems started on 12.12: #1051834814896013332 and #1053088070041346059 message (For some reason the # link doesn't work there) respectively.

crude badger
#

I ended up with a loop hitting the endpoint until the request got through - nothing to write home about ....

bronze locust
#

Yes, that is how everyone has bypassed it so far, some form of retry.

elder iris
#

bypassed what? the problem has never been properly described