I’m working on this project for a few months now, the script is working but somehow it crashes without giving errors randomly, so now I’m wondering if exist a way to do it better.
def request_data(id):
#HTTP REQUEST
link = ‘https://api.twitch.tv/kraken/streams/’ + id
accept = ‘application/vnd.twitchtv.v5+json’
client_id = ‘b694vntu5if2kpjcbm0l7migfm6x99’
r1 = r2 = r3 = data = None
print('entro in request_data')
print('entro in request_data primo try')
try:
r1 = requests.get(link, headers={'Client-ID':client_id, 'Accept': accept})
except Exception as error:
print('(1)Error: '+ str(error))
return data
time.sleep(1) #sec
if r1.status_code == 200:
print('entro in request_data r1.status_code == 200')
try:
r2 = r1.text
except:
print('(2)Error: '+ str(error))
return data
if 'stream' in r2:
print('entro in request_data "stream" in r2')
try:
r3 = r1.json()['stream']
except Exception as error:
print('(3)Error: '+ str(error))
return data
print('entro in request_data secondo try')
if r3 != None:
print('entro in request_data r3 != None')
try:
data = r3['broadcast_platform']
except Exception as error:
print('(4)Error: '+ str(error))
print('fine in request_data')
return data`
I don’t think is normal that I’ve to put all this TRY CATCH for let it workin…