handle null headers
This commit is contained in:
parent
13d9a85055
commit
995aeb1ff0
@ -8,6 +8,7 @@ Supported exchanges:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from cachetools import cached
|
from cachetools import cached
|
||||||
@ -106,12 +107,13 @@ class BinanceAnnouncement(AnnouncementMixin):
|
|||||||
raise TemporaryError(f"Binance url ({url}) is not available. Original Exception: {e}")
|
raise TemporaryError(f"Binance url ({url}) is not available. Original Exception: {e}")
|
||||||
|
|
||||||
if not history:
|
if not history:
|
||||||
while 'Age' in response.headers:
|
while 'Age' in (response.headers or {}):
|
||||||
try:
|
try:
|
||||||
url = self.get_api_url(random.randint(1, 100), page_size)
|
url = self.get_api_url(random.randint(1, 100), page_size)
|
||||||
response = get(url, headers=headers)
|
response = get(url, headers=headers)
|
||||||
except Exception:
|
except Exception:
|
||||||
break
|
break
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise TemporaryError(f"Invalid response from url: {url}.\n"
|
raise TemporaryError(f"Invalid response from url: {url}.\n"
|
||||||
@ -120,8 +122,8 @@ class BinanceAnnouncement(AnnouncementMixin):
|
|||||||
|
|
||||||
logger.info("Updating from Binance...")
|
logger.info("Updating from Binance...")
|
||||||
updated_list = []
|
updated_list = []
|
||||||
|
articles = response.json()['data']['articles'] or []
|
||||||
for article in response.json()['data']['articles']:
|
for article in articles:
|
||||||
article_link = self.get_announcement_url(article['code'])
|
article_link = self.get_announcement_url(article['code'])
|
||||||
article_text = article['title']
|
article_text = article['title']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user