Skip to content
Permalink
Browse files

DK with a retry

  • Loading branch information...
corradio committed Mar 29, 2019
1 parent 7dca380 commit bdc5f601f537e4b0399e50e5ca218611ae77e1cd
Showing with 8 additions and 0 deletions.
  1. +8 −0 parsers/DK.py
@@ -3,6 +3,7 @@
import arrow # the arrow library is used to handle datetimes
import requests # the request library is used to fetch content through HTTP
import pytz
import time
from .lib.exceptions import ParserException


@@ -44,6 +45,13 @@ def fetch_production(zone_key='DK-DK1', session=None,target_datetime=None,
response = r.get(url)

# raise errors for responses with an error or no data
if response.status_code == 429:
# Wait and retry
logger.warn('429: Retrying..')
time.sleep(10)
response = r.get(url)
if response.status_code == 429:
raise Exception('429 status code obtained after retrying..')
if response.status_code != 200:
error = response.json()['error']['__type']
text = response.json()['error']['info']['orig']

0 comments on commit bdc5f60

Please sign in to comment.
You can’t perform that action at this time.