Problems with the OAuth token

I’m currently working on what seemed to me a simple project using the Twitch API in a Python program on my desktop. All I want the program to do is to capture every message written in a Twitch channel’s chat and for each new message, add 1 second to a timer made in HTML. So, I’ve obtained TWITCH_CLIENT_ID, TWITCH_TOKEN, TWITCH_CLIENT_SECRET. However, every time I try to call anything, I get a 401 Client Error: Unauthorized for URL. And, as I understood and was explained on the internet, I need to check and modify the format and permission of the Auth token. I assume the problem is probably with this? How to solve this problem in a Python program? Thank you!

1 Like

For reading chat are you trying to connect to Chat over IRC or over EventSub?

When you get a 401 what URL or API request are you attempting?

Sorry, I’m a complete novice in programming, and I’ve been helped to implement this artificial intelligence idea. If I send you the code that triggers this error, would it help you understand the situation?

That would be useful yes.

import twitchio

# Your credentials
TWITCH_TOKEN = "oauth:"

async def check_connection():
        # Creating a Twitch client
        bot = twitchio.Client(

        # Connecting to Twitch chat
        await bot.start()
        print("Successfully connected to Twitch chat!")

    except twitchio.exceptions.AuthenticationError as e:
        print("Authentication error:", e)
    except Exception as e:
        print("An error occurred while connecting:", e)
        # Closing the connection
        await bot.close()

# Running the connection check script
if __name__ == "__main__":
    import asyncio

Theres nothing here that would surface the error you have reported.

Since you are using twitchio you might fare better in the twitchio focussed rooms on the Libraries Discord:

Understood, thank you.