Hi i try to request some json, all is ok, but sometimes request goes wrong, may be site stack or closing connection for me, cause i am requesting json every 15 min.
Code here:
def request_coins(config):
coins = None
print(str(datetime.now()) + ' - REQUESTING Coins')
while coins is None:
try:
coins = (requests.get(url=str(config['UrlPath']['url']) + str(config['UrlPath']['userrates'])))
except:
print(str(datetime.now()) + " - Site didn't respond. Reconnecting in 10 sec")
time.sleep(10)
if coins is not None:
coins = coins.json()['coins']
print(str(datetime.now()) + ' - Coins received correctly')
return coins
Problems is that try - catch don't work in my case. Request stack in print(str(datetime.now()) + ' - REQUESTING Coins')
and i don't recieve any exception and message to cmd
print(str(datetime.now()) + " - Site didn't respond. Reconnecting in 10 sec")
As I understood code stacks at try:
coins = (requests.get(url=str(config['UrlPath']['url']) +
str(config['UrlPath']['userrates'])))
and don't go even to except
:
Any idea how to fix?