How to use the twitchio.errors.AuthenticationError function in twitchio

To help you get started, we’ve selected a few twitchio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TwitchIO / TwitchIO / twitchio / websocket.py View on Github external
except asyncio.InvalidStateError:
                    pass

                if fut.done():
                    futures.remove(fut)

            if futures:
                await asyncio.wait(futures)

            await self._dispatch('ready')
            self.is_ready.set()

        elif data == ':tmi.twitch.tv NOTICE * :Login authentication failed' or\
                data == ':tmi.twitch.tv NOTICE * :Improperly formatted auth':
            log.warning('Authentication failed | %s', self._token)
            raise AuthenticationError('Websocket Authentication Failure... Check your token and nick.')

        _groupsdict = {}

        if data.startswith("PING"):
            match = self.regex["ping"]
        else:
            match = self.regex["data"]

        result = match.match(data)

        badges = self.regex['badges'].match(data)

        if badges:
            badges = {'name': badges.group('name'), 'mod': badges.group('mod'), 'action': badges.group('action'),
                      'channel': badges.group('channel')}
github TwitchIO / TwitchIO / twitchio / websocket.py View on Github external
def _task_callback(self, data, task):
        exc = task.exception()

        if isinstance(exc, AuthenticationError):
            self._authentication_error = True
        elif exc:
            self.loop.create_task(self.event_error(exc, data))
github TwitchIO / TwitchIO / twitchio / websocket.py View on Github external
async def _listen(self):
        backoff = ExponentialBackoff()

        if not self.is_connected and self._last_exec:
            raise WSConnectionFailure(f'Websocket connection failure:\n\n{self._last_exec}')

        while True:
            if self._authentication_error:
                log.error('AUTHENTICATION ERROR:: Incorrect IRC Token passed.')
                raise AuthenticationError

            try:
                data = await self._websocket.recv()
            except websockets.ConnectionClosed:
                retry = backoff.delay()
                log.info('Websocket closed: Retrying connection in %s seconds...', retry)

                await asyncio.sleep(retry)
                await self._connect()
                continue

            await self._dispatch('raw_data', data)

            _task = self.loop.create_task(self.process_data(data))
            _task.add_done_callback(functools.partial(self._task_callback, data))