BasioMeusPuga/twitchy

Error communicating with Twitch API ('NoneType' object is not subscriptable)

r3-l5-r3 opened this issue · 6 comments

Just updated via the AUR to the most recent release; twitchy crashes when trying to check channel statuses (e.g. by just executing twitchy) , with this error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/twitchy/twitchy_api.py", line 260, in get_game
    'EQUALS')[0]
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/twitchy", line 11, in <module>
    load_entry_point('twitchy==3.1.0', 'console_scripts', 'twitchy')()
  File "/usr/lib/python3.6/site-packages/twitchy/__main__.py", line 393, in main
    watch_channel(None)
  File "/usr/lib/python3.6/site-packages/twitchy/__main__.py", line 189, in watch_channel
    id_string_list).check_channels()
  File "/usr/lib/python3.6/site-packages/twitchy/twitchy_api.py", line 354, in check_channels
    game_data = self.get_game(game_id)
  File "/usr/lib/python3.6/site-packages/twitchy/twitchy_api.py", line 270, in get_game
    game_name = game_details[0][1].replace("'", "")
IndexError: list index out of range

(Aside: I don't know if this is intentional, but AUR package version numbers and git release commit numbers aren't consistent, threw me off for a bit; e.g. AUR package r31.38f8c54-1 retrieves release r185.214c8c0-1 from the git repo.)

Hey,

I've only been able to replicate this in case of the function that's erroring out being fed an invalid game_id. Now that's something that reported by the API itself. So this shouldn't be happening.

Therefore, I'm going to need a little more information. The fastest way about that is putting a

print(r.url)

as line 28 of the twitchy_api module. Or use this patch here: https://pastebin.com/8m77WAbd
It would also really help if you would include a copy of your twitchy.db from ~/.config/twitchy3/twitchy.db

The AUR version thing was an oversight. Didn't make too much of it since those numbers update by themselves. That's fixed.

So I've checked just now, seems like the error has gone away (possibly due to the invalid game_id no longer being a thing?), and I can use the API with twitchy as normal.

Just for reference, I've added the print line manually to the twitchy_api module, and here's what's output from running twitchy:

 Checking 82 channel(s)...
https://api.twitch.tv/helix/streams?first=100&user_id=117559435&user_id=28577337&user_id=39677999&user_id=156604798&user_id=43036528&user_id=167770652&user_id=27942990&user_id=145497793&user_id=20048794&user_id=28036730&user_id=118999468&user_id=31736255&user_id=30923466&user_id=138683413&user_id=140820291&user_id=73454326&user_id=22454901&user_id=50905707&user_id=67015369&user_id=12256249&user_id=23125739&user_id=85093893&user_id=75346877&user_id=134808512&user_id=130762761&user_id=135424527&user_id=26350129&user_id=113844239&user_id=37048838&user_id=37113607&user_id=33286185&user_id=57781936&user_id=97683586&user_id=56751854&user_id=20483303&user_id=112865684&user_id=40755787&user_id=29220001&user_id=91029784&user_id=119737288&user_id=29014019&user_id=59386687&user_id=118485573&user_id=12616386&user_id=35653658&user_id=26487885&user_id=50103506&user_id=49664224&user_id=88047948&user_id=31692978&user_id=36685283&user_id=57670730&user_id=37096992&user_id=81686852&user_id=6594408&user_id=40594186&user_id=30992665&user_id=24629203&user_id=26605147&user_id=81195314&user_id=63759987&user_id=63605003&user_id=50251439&user_id=57517765&user_id=14684490&user_id=20693004&user_id=21615575&user_id=22711983&user_id=8160994&user_id=29478753&user_id=40669301&user_id=5834235&user_id=9652726&user_id=27306499&user_id=20739344&user_id=14717297&user_id=19336638&user_id=14371185&user_id=320878&user_id=27150884&user_id=174025954&user_id=36029255
 League of Legends
 1 Riot Games            98,955       Worlds 2017 Semifinals: SK telecom...
 Number? 

Here's my database file (I've compressed it to a .gz file to comply with GitHub's restrictions on file uploads for threads):
twitchy.db.gz

Sorry for not replying earlier; I'll check again later to see if the problem re-appears. I've also updated my twitchy installation again via AUR to match version numbers, but that shouldn't be relevant to the above issue, I'm guessing.

Wait, I am getting a somewhat different error though. I'm unable to use twitchy -w <channel> to open streams; the following comes up when I try to open a stream (that is currently online) this way (e.g. twitchy -w nusuey):

https://api.twitch.tv/helix/users?login=n&login=u&login=s&login=u&login=e&login=y
 No valid channels.

...I don't know if this is related to the above issue, but it is an issue that I did have earlier on as well (sorry, forgot to mention this earlier).

EDIT: Also worth noting, using twitchy --non-interactive kickstart <channel> does load the stream and open the browser chat popout as normal.

So I checked your twitchy.db file. One of the game names is blank. This happens when a streamer does not set a game name for whatever reason. I'm assuming that is what was getting passed to the function which was causing it to get a null return, and therefore to error out.

The -w thing is fixed.

Tell me if this changes anything or the errors return?

Replaced the __main__.py and twitchy_api.py with the newest version that includes your fixes, and it seems to be handling it correctly. I can't tell for sure, since it seems like none of the channels in the database haven't set a game name (at this point in time).

Can confirm the -w thing is fixed. Thanks for helping me out with the issues; I'll report back if I see them reappear again for whatever reason.