Getting error 401 on a single channel, but with others everything is ok

I’m facing a strange problem, looping over a few username to get their respective IDs, but one gives me 401 error. I’m posting the one that returns me error and another working fine so you all can see.

The one that’s giving error.

link = 'https://api.twitch.tv/helix/users?login=' + username
>>> https://api.twitch.tv/helix/users?login=cerbero_podcast
async with aiohttp.ClientSession() as session:
    async with session.get(link, headers={'Client-ID': client_id, 'Authorization': twitch_token}) as resp:
        >>> print(resp)
<ClientResponse(https://api.twitch.tv/helix/users?login=cerbero_podcast) [401 Unauthorized]>
<CIMultiDictProxy('Connection': 'keep-alive', 'Content-Length': '69', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-cache, no-store, must-revalidate, private', 'Content-Type': 'application/json; charset=utf-8', 'Expires': '0', 'Pragma': 'no-cache', 'Server': 'envoy', 'timing-allow-origin': 'https://www.twitch.tv', 'twitch-trace-id': 'd2187cbca3a82dfc22c46ab9d8b61798', 'x-ctxlog-logid': '1-5ed6531d-3fb73c2bac2dab247b99b540', 'Date': 'Tue, 02 Jun 2020 13:24:45 GMT', 'X-Served-By': 'cache-sea4462-SEA, cache-fra19143-FRA', 'X-Cache': 'MISS, MISS', 'X-Cache-Hits': '0, 0', 'X-Timer': 'S1591104285.098942,VS0,VS0,VE160', 'Vary': 'Accept-Encoding', 'Strict-Transport-Security': 'max-age=300')>

The one that’s working fine.

link = 'https://api.twitch.tv/helix/users?login=' + username
>>> https://api.twitch.tv/helix/users?login=berritv
async with aiohttp.ClientSession() as session:
    async with session.get(link, headers={'Client-ID': client_id, 'Authorization': twitch_token}) as resp:
        >>> print(resp)
<ClientResponse(https://api.twitch.tv/helix/users?login=berritv) [200 OK]>
<CIMultiDictProxy('Connection': 'keep-alive', 'Content-Length': '453', 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'no-cache, no-store, must-revalidate, private', 'Content-Type': 'application/json; charset=utf-8', 'Expires': '0', 'Pragma': 'no-cache', 'ratelimit-limit': '800', 'ratelimit-remaining': '799', 'ratelimit-reset': '1591104287', 'Server': 'envoy', 'timing-allow-origin': 'https://www.twitch.tv', 'twitch-trace-id': '12b8372efccfe6b92d006f3aef34b050', 'x-ctxlog-logid': '1-5ed6531e-dfcf49f09b484604f680f043', 'Date': 'Tue, 02 Jun 2020 13:24:46 GMT', 'X-Served-By': 'cache-sea4430-SEA, cache-fra19149-FRA', 'X-Cache': 'MISS, MISS', 'X-Cache-Hits': '0, 0', 'X-Timer': 'S1591104286.401778,VS0,VS0,VE180', 'Vary': 'Accept-Encoding', 'Strict-Transport-Security': 'max-age=300')>

What does the body/message of the error say?

Also you do preceed your token with Bearer like so: Bearer TOKEN?

Your code suggests you may have omitted the BearerSPACE

1 Like

I don’t know that’s why I asked. you didn’t post any code about how the access token is obtained.

And to display the body/message, what language is this? Looks like C or a derivative there of, you’d get the error message the same way you would get a success body, ie the data of the user you requested

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.