TypeError: object of type 'NoneType' has no len()
See original GitHub issueSentry Issue: SIR-LANCEBOT-8R
TypeError: object of type 'NoneType' has no len()
File "discord/ext/commands/core.py", line 190, in wrapped
ret = await coro(*args, **kwargs)
File "bot/exts/holidays/halloween/scarymovie.py", line 23, in random_movie
selection = await self.select_movie()
File "bot/exts/holidays/halloween/scarymovie.py", line 50, in select_movie
selection_id = random.choice(data.get("results")).get("id")
File "random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
Unhandled command error: object of type 'NoneType' has no len()
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Python: TypeError: object of type 'NoneType' has no len()
Drop the assignment. This function returns None and that's why you have the error: TypeError: object of type 'NoneType' has no len().
Read more >Python TypeError: object of type 'NoneType' has no len()
The “TypeError: object of type 'NoneType' has no len() ” error is caused when you try to use the len() method on an...
Read more >TypeError: object of type 'NoneType' has no len() - Yawin Tutor
The TypeError: object of type 'NoneType' has no len() error occurs while attempting to find the length of an object that returns 'None'....
Read more >TypeError: object of type 'NoneType' has no len() - STechies
This error is generated in Python when we try to calculate the length of an object which returns 'none'. Let us understand it...
Read more >Solve Python TypeError: object of type 'NoneType' has no len()
The “TypeError: object of type 'NoneType' has no len()” error in Python occurs when you try to call the len function on an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, that sounds good.
Right, I see. For some reason I was thinking that the initial response would include all entries, which isn’t actually the case as you stated (it seems to return 20).
It seems like a smart thing to do for future-proofing. Seems it needs to be limited to a max of 500 (not the 1000 stated on the API’s docs)?.
I don’t think there’s any reason it should be
None
so probably send a message to the user saying no results were found and maybe log a warning so we can look into it.The first request is to get the number of pages so one can be selected for the request. If we used the results from the first request we’d be much more limited in the results we got.
Side note: we may also want a fix like https://github.com/python-discord/sir-lancebot/issues/1055, it’s the same API and similar use case, just in a different place. It’s possible it isn’t an issue in practice for this genre if the total count isn’t high enough though.