[Python]I can't make !uptime command for my bot

My bot joins my chat perfectly and respond any other commands but uptime command doesn’t work. I’m very new to this chat bot thing.

Error I got:
Traceback (most recent call last):
File “./bot.py”, line 152, in
File “./bot.py”, line 39, in get_stream_uptime
if get_stream_status():
File “./bot.py”, line 35, in get_stream_status
if online_data[‘stream’] != None:
KeyError: ‘stream’

My Bot:

  1. Remove you PASS from the hastebin
  2. The problem is that your request code is a) Not checking the HTTP Status Response and b) passing no headers.

So you are making a request to a API v5 URL but asking for the default of a v3 response.

You need to add a header to your requests.get of Accept: application/vnd.twitchtv.v5+json

I’m not familiar with python’s request function, so you’ll have to look that up yourself.

Even if I try with v3 url it’s not responding and giving the same error.

If you haven’t already, I would change your password if you put it on a public paste site – And probably regenerate your applications secret key to be safe. (Anybody who subscribes to emails from twitch dev forums still has access to the password.)

Re: The original post,

If the stream is offline it returns a null object, not a stream object (you will also get a null object if you had a web exception, such as not passing a ClientID]. You need to check if your api object is null first, and if not, THEN do your checks.

I would recommend also catching web exceptions (whatever that looks like in python) and printing the http status code + error message if you get one.

Re: @BarryCarlyon 's point, you need to either send your ClientID as a header value in your api request, or as a ?client_id=xxxxxx at the end of the url.

Not entirely sure but I think my library (asynctwitch) supports it.

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