chat-downloader icon indicating copy to clipboard operation
chat-downloader copied to clipboard

AttributeError: 'NoneType' object has no attribute 'get'

Open artiction opened this issue 3 years ago • 3 comments

Basic information

  • Program version: 0.1.5
  • Python version: 3.9.0
  • Operating system: Windows 10

Command/Code used

python -m chat_downloader -v --message_types "text_message paid_message membership_item" --cookies C:\sf.txt https://www.youtube.com/watch?v=Yqee5kO8zu0 -o Yqee5kO8zu0.txt

If running from the command line, provide the following:

  1. The command used (including the verbose tag, -v):
python -m chat_downloader -v --message_types "text_message paid_message membership_item" --cookies C:\sf.txt https://www.youtube.com/watch?v=Yqee5kO8zu0 -o Yqee5kO8zu0.txt
  1. Output from the above command:
[DEBUG] Python version: 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
[DEBUG] Program version: 0.1.5
[DEBUG] Initialisation parameters: {'headers': None, 'cookies': 'C:\\sf.txt', 'proxy': None}
[DEBUG] Created YouTubeChatDownloader session.
[INFO] Site: youtube.com
[DEBUG] Program parameters: {'url': 'https://www.youtube.com/watch?v=Yqee5kO8zu0', 'start_time': None, 'end_time': None, 'max_attempts': 15, 'retry_timeout': None, 'timeout': None, 'inactivity_timeout': None, 'max_messages': None, 'message_groups': ['messages'], 'message_types': ['text_message', 'paid_message', 'membership_item'], 'output': 'Yqee5kO8zu0.txt', 'overwrite': True, 'sort_keys': True, 'indent': 4, 'format': 'youtube', 'format_file': None, 'chat_type': 'live', 'ignore': None, 'message_receive_timeout': 0.1, 'buffer_size': 4096}
[DEBUG] Starting new HTTPS connection (1): www.youtube.com:443
[DEBUG] https://www.youtube.com:443 "GET /watch?v=Yqee5kO8zu0 HTTP/1.1" 200 None
[DEBUG] Match found: "<re.Match object; span=(0, 43), match='https://www.youtube.com/watch?v=Yqee5kO8zu0'>". Running "_get_chat_by_video_id" function in "YouTubeChatDownloader".
[DEBUG] Chat information: {'chat': <generator object YouTubeChatDownloader._get_chat_messages at 0x0000020EBEA4C820>, 'callback': <function ChatDownloader.get_chat.<locals>.<lambda> at 0x0000020EBDC9BB80>, 'title': "【Ethyria】UNO?! DOS?! TRES?! Millie's POV✨  ☆⭒NIJISANJI EN ✧ Millie Parfait ☆⭒", 'duration': 0, 'is_live': True, 'start_time': None, 'format': <function ChatDownloader.get_chat.<locals>.<lambda> at 0x0000020EBDC76F70>, 'site': <chat_downloader.sites.youtube.YouTubeChatDownloader object at 0x0000020EBDC4F640>}
[INFO] Retrieving chat for "【Ethyria】UNO?! DOS?! TRES?! Millie's POV✨  ☆⭒NIJISANJI EN ✧ Millie Parfait ☆⭒".
[DEBUG] Getting Live chat (Live chat).
[DEBUG] https://www.youtube.com:443 "GET /live_chat?continuation=0ofMyANhGlhDaWtxSndvWVZVTTBOM0pPYld0RVkwNW5ZazlqVFMweVFuZDZTbFJSRWd0WmNXVmxOV3RQT0hwMU1Cb1Q2cWpkdVFFTkNndFpjV1ZsTld0UE9IcDFNQ0FCMAGCAQIIAQ%3D%3D HTTP/1.1" 200 None
[DEBUG] Continuation parameters: {'click_tracking': {'clickTrackingParams': 'IhMIuf34n/va8wIVIAG3AB0OowoW'}, 'continuation': '0ofMyANhGlhDaWtxSndvWVZVTTBOM0pPYld0RVkwNW5ZazlqVFMweVFuZDZTbFJSRWd0WmNXVmxOV3RQT0hwMU1Cb1Q2cWpkdVFFTkNndFpjV1ZsTld0UE9IcDFNQ0FCMAGCAQIIAQ%3D%3D'}
[DEBUG] Session headers: User-Agent, Accept-Language, origin, x-youtube-client-name, x-youtube-client-version, x-origin, x-goog-authuser, x-youtube-identity-token, x-goog-visitor-id, authorization, content-type, referer
[DEBUG] Logged-in info: {'key': 'logged_in', 'value': '1'}
[DEBUG] Session closed.
Traceback (most recent call last):
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\__main__.py", line 4, in <module>
    main()
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\cli.py", line 188, in main
    run(**args.__dict__)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\chat_downloader.py", line 360, in run
    for message in chat:
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\sites\common.py", line 240, in __next__
    item = next(self.chat)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\sites\youtube.py", line 1479, in _get_chat_messages
    parsed_header = self._parse_item(header)
  File "C:\Users\x\AppData\Local\Programs\Python\Python39\lib\site-packages\chat_downloader\sites\youtube.py", line 502, in _parse_item
    item_info = item.get(item_index)
AttributeError: 'NoneType' object has no attribute 'get'

Additional context/information

I can solve this bug by using the line without cookies, it seems that this bug is very specific to some videos since this happens pretty rarely at times.

artiction avatar Oct 21 '21 07:10 artiction

While this likely won't solve your issue, know that chat_downloader is currently at version 0.1.10, not 0.1.5.

Related to the video, there's two unusual things: one is a trailer, the other is a 8 hour old poll. While I've downloaded chats with polls before, I'm not sure if I've ever done it with cookies. I've been downloading that same video since 02:43:48 (AM) EDT, without cookies, and I haven't had any issue so far.

krichbanana avatar Oct 21 '21 15:10 krichbanana

Something to add, I don't think it's the trailer since this happened to another channel with no trailer for their upcoming stream, so yeah. I'm just afraid if this exact bug happens to a members stream where I need cookies to grab the chat.

artiction avatar Oct 29 '21 10:10 artiction

You could try downloading the live chat with a recent yt-dlp (not youtube-dl), it should support upcoming member streams with cookies : yt-dlp -v --cookies <cookies.txt> --ignore-no-formats-error --all-subs --skip-download <video>

It does not do any extra processing on the received JSON to my knowledge, so the file format will be a bit different, but if the chat successfully downloads with that program then it will provide a clue as to what causes chat_downloader to fail.

krichbanana avatar Oct 29 '21 14:10 krichbanana

This has been fixed in https://github.com/xenova/chat-downloader/pull/177 (and is now live in v0.2.1)

xenova avatar Nov 30 '22 23:11 xenova