sir-lancebot icon indicating copy to clipboard operation
sir-lancebot copied to clipboard

KeyError: 'status_code' in movie command

Open sentry[bot] opened this issue 3 years ago • 4 comments

Sentry Issue: SIR-LANCEBOT-85

KeyError: 'status_code'
  File "discord/ext/commands/core.py", line 167, in wrapped
    ret = await coro(*args, **kwargs)
  File "bot/exts/fun/movie.py", line 94, in movies
    err_msg = f"There is problem while making TMDB API request. Response Code: {result['status_code']}, " \

Unhandled command error: 'status_code'

sentry[bot] avatar May 10 '22 18:05 sentry[bot]

There are two issues here. Firstly, the reason the request fails is that the command fetches a random page up to the total number of pages https://github.com/python-discord/sir-lancebot/blob/6609ceab1600ae5d08c2614f5a0f994b86f8ba5e/bot/exts/fun/movie.py#L88-L89 However the page parameter is documented as only allowing a maximum page numer of 1000 (https://developers.themoviedb.org/3/discover/movie-discover). You can replicate this by running .movies Drama (may need to run it a few times if it chooses a valid page number first).

The second issue is with the error handling. There is no status_code documented in the response JSON. We should instead detect errors based on the return code of the request

wookie184 avatar May 10 '22 18:05 wookie184

I would like to work on this issue.

CyberCitizen01 avatar May 20 '22 14:05 CyberCitizen01

Also, maximum page number doesn't seem to be 1000 (though it is documented as such), but 500?

curl "https://api.themoviedb.org/3/discover/movie?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&page=999&with_genres=18"

Response Status code: 422

{
  "errors": [
    "page must be less than or equal to 500"
  ]
}

I'm guessing this is because I'm a new user?

CyberCitizen01 avatar May 20 '22 14:05 CyberCitizen01

I checked our bot and we get the same "page must be less than or equal to 500" so it seems the API docs may be wrong, good spot! We should probably limit it to 500 then.

wookie184 avatar May 20 '22 17:05 wookie184