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 hook start after Eventsub hook stop #188

Closed stolenvw closed 1 year ago

stolenvw commented 1 year ago

Trying to start the eventsub hook after stopping it gives an error of ip port is in use.

with debug logging enabled don't get the we got cancelled i do get the messages about it making the delete request, and unsubscribe from event

stolenvw commented 1 year ago

OAuth has the same problem

Log:

2023-01-18 18:14:37 - INFO - twitchAPI.oauth: running oauth Webserver
2023-01-18 18:14:43 - DEBUG - twitchAPI.oauth: got callback with state <Removed stat code>
2023-01-18 18:14:54 - INFO - twitchAPI.oauth: shutting down oauth Webserver

Error when trying to start it again:

Exception in thread Thread-4 (__run):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/test-twitch-bot/.twitchtestenv/lib/python3.10/site-packages/twitchAPI/oauth.py", line 298, in __run
    self.__loop.run_until_complete(site.start())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/user/test-twitch-bot/.twitchtestenv/lib/python3.10/site-packages/aiohttp/web_runner.py", line 121, in start
    self._server = await loop.create_server(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 1505, in create_server
    raise OSError(err.errno, 'error while attempting '
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 17563): address already in use
Tempystral commented 1 year ago

I had to redo the webserver portion of the oauth code for my own authentication flow and I ran into this issue when I tried to run my app. I added reuse_address=True to the TCPSite and added await runner.cleanup() to the shutdown procedure in the run check. Now I can launch and relaunch my webserver just fine. I suspect a similar change is all that would be required for oauth.