Skip to content

Commit

Permalink
DK with a retry
Browse files Browse the repository at this point in the history
  • Loading branch information
corradio committed Mar 29, 2019
1 parent 7dca380 commit bdc5f60
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions parsers/DK.py
Expand Up @@ -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


Expand Down Expand Up @@ -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']
Expand Down

0 comments on commit bdc5f60

Please sign in to comment.