Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

EventSub? bug with keeping connection alive #124

Closed Daenara closed 1 year ago

Daenara commented 2 years ago

Hello, me again, more aiohttp errors, this time I have no idea where they come from exactly, but my best guess would be this library. The only other place aiohttp is used is in the small webserver I use for overlays and notifications and that one does not have any recurring tasks, it just answers when someone opens the website, this looks more like keeping a connection alive. My best guess is that it is eventsub, since the reason I looked into the log file on the server (yes, not my broken test setup this time) to begin with was that the bot does not notice when a stream goes offline. I added more output to find out if my callbacks even trigger and wanted to look at the log before I go and start streaming, just in case.

When I restarted the bot on the server it was Aug 15 19:30 (roughly) eventsub was loaded without error, the restart happened because the bot did not notice me going live. Going back up, those errors occur pretty regularly ever since I switched the online/offline/status changed detection to eventsub. I will continue trying to figure out if my callbacks are even called, but I thought I would drop this in here in case it helps you with anything. If it helps in any way, I am happy to plaster my code with debug output or try catch blocks, I just need someone to tell me where I need to put it to catch more information about this specific issue.

Daenara

Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-15 22:11:05,345 aiohttp.server ERROR: Error handling request
Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 15 22:11:05 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadHttpMessage: 400, message='Pause on PRI/Upgrade'
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-16 03:06:06,755 aiohttp.server ERROR: Error handling request
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 16 03:06:06 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-16 17:09:55,460 aiohttp.server ERROR: Error handling request
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 16 17:09:55 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-17 02:48:40,281 aiohttp.server ERROR: Error handling request
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 17 02:48:40 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-17 06:48:57,412 aiohttp.server ERROR: Error handling request
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 17 06:48:57 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-17 10:32:23,565 aiohttp.server ERROR: Error handling request
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 17 10:32:23 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-17 18:36:07,715 aiohttp.server ERROR: Error handling request
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 17 18:36:07 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encoun>
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: 2022-08-17 18:36:09,369 aiohttp.server ERROR: Error handling request
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: Traceback (most recent call last):
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "/home/humandotexe/TwitchBot/venv/lib/python3.9/site-packages/aiohttp-3.8.1-py3.9-li>
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:     messages, upgraded, tail = self._request_parser.feed_data(data)
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]:   File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
Aug 17 18:36:09 799e5c28-e4e3-4383-8919-e6cd53f575fa python3[18647]: aiohttp.http_exceptions.BadHttpMessage: 400, message='Pause on PRI/Upgrade'
Teekeks commented 2 years ago

Did you manage to fix your previous network problems? These errors do not look like they are directly related to this library but again to something going on with weird network problems.

Daenara commented 2 years ago

This is the server it runs on, the other problem was my local setup. Sadly nothing to do with each other, only the same code running on it. I can't tell you for sure they are caused by your library, they just looked similar enough to the other error that I know is caused by eventsub if it runs into a timeout, so I thought this might be eventsub related also, maybe twitch is sending strange packages for a keepalive from time to time or something, I can only guess.

Daenara commented 2 years ago

I also just checked my debug output that I put into my eventsub callback. Good news it is worked this time and did what it should, but something about it was strange. When I started the stream I got a callback for stream offline, followed by a stream online callback, eventsub definitely works, but it seems stream is pretty strange with sending the callbacks.

Teekeks commented 1 year ago

Does this problem still exist in the current versions?

Teekeks commented 1 year ago

after further investigation: this is pretty surely purely a network connection problem that I cant fix.