Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandled missing v5/Commenter causes crash #34

Open
mgrandi opened this issue Mar 15, 2021 · 0 comments
Open

unhandled missing v5/Commenter causes crash #34

mgrandi opened this issue Mar 15, 2021 · 0 comments

Comments

@mgrandi
Copy link

mgrandi commented Mar 15, 2021

running tcd fails on a certain video because it seems the user the comment belongs to doesn't exist anymore or something, so the twitch api returns 'null' for that field, which twitch-python doesn't handle and throws a NPE

(tcd_venv) PS C:\Users\mark\Code\Personal\git\get_twitch_vod_chats> tcd --verbose --video 873505779 --format "json,default,irc,srt,ssa" --debug --output "tcd_output.log" --timezone "UTC"
NES speedruns
Downloading JSON data
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\mark\Temp\tcd_venv\Scripts\tcd.exe\__main__.py", line 7, in <module>
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\tcd\__init__.py", line 92, in main
    Downloader().videos(Arguments().video_ids)
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\tcd\downloader.py", line 183, in videos
    self.video(video)
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\tcd\downloader.py", line 100, in video
    for comment in video.comments:
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\twitch\v5\resources\comments.py", line 27, in __iter__
    yield v5.Comment(api=self._api, data=comment)
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\twitch\v5\models\comment.py", line 84, in __init__
    self.commenter: Commenter = Commenter(data.get('commenter'))
  File "c:\users\mark\temp\tcd_venv\lib\site-packages\twitch\v5\models\comment.py", line 18, in __init__
    self.display_name: str = data.get('display_name')
AttributeError: 'NoneType' object has no attribute 'get'

i added logging to both tcd and twitch-python (which i feel you should add to both as an aside, would have made it easier to debug) and as the video will probably be aged out by the time you look at this, i have the full api response output if you want.

Here is the relevant api response (a python dict, not JSON), note the None as the value for commenter

              {'_id': 'f1887ffa-1831-48f0-a989-26b5535b3627',
               'channel_id': '26642416',
               'commenter': None,
               'content_id': '873505779',
               'content_offset_seconds': 10472.579,
               'content_type': 'video',
               'created_at': '2021-01-14T21:54:30.279Z',
               'message': {'body': 'rambo!',
                           'fragments': [{'text': 'rambo!'}],
                           'is_action': False,
                           'user_badges': [{'_id': 'subscriber',
                                            'version': '3'},
                                           {'_id': 'premium', 'version': '1'}],
                           'user_notice_params': {}},
               'source': 'chat',
               'state': 'published',
               'updated_at': '2021-01-14T21:54:30.279Z'},

its fixed by adding a check to see if data.get("commenter") is none, and if so, just set self.commenter = None in v5/models/commenter.py : Comment.__init__, however all of the formatters except for JSON expect a commenter, so those parts of the code need to handle a potential missing commenter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant