fixed bug with timeout

This commit is contained in:
Hellow2 2023-04-04 10:05:37 +02:00
parent 98fb2c7bf9
commit b1a8410376
3 changed files with 14 additions and 3 deletions

View File

@ -62,6 +62,7 @@ class Page:
API_SESSION: requests.Session = requests.Session() API_SESSION: requests.Session = requests.Session()
API_SESSION.proxies = shared.proxies API_SESSION.proxies = shared.proxies
TIMEOUT = 5 TIMEOUT = 5
POST_TIMEOUT = TIMEOUT
TRIES = 5 TRIES = 5
LOGGER = LOGGER LOGGER = LOGGER
@ -75,8 +76,10 @@ class Page:
try: try:
r = cls.API_SESSION.get(url, timeout=cls.TIMEOUT, stream=stream) r = cls.API_SESSION.get(url, timeout=cls.TIMEOUT, stream=stream)
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
cls.LOGGER.warning(f"request timed out at \"{url}\": ({trie}-{cls.TRIES})")
retry = True retry = True
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
cls.LOGGER.warning(f"couldn't connect to \"{url}\": ({trie}-{cls.TRIES})")
retry = True retry = True
if not retry and r.status_code in accepted_response_codes: if not retry and r.status_code in accepted_response_codes:
@ -97,10 +100,12 @@ class Page:
requests.Response]: requests.Response]:
retry = False retry = False
try: try:
r = cls.API_SESSION.post(url, json=json, timeout=cls.TIMEOUT) r = cls.API_SESSION.post(url, json=json, timeout=cls.POST_TIMEOUT)
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
cls.LOGGER.warning(f"request timed out at \"{url}\": ({trie}-{cls.TRIES})")
retry = True retry = True
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
cls.LOGGER.warning(f"couldn't connect to \"{url}\": ({trie}-{cls.TRIES})")
retry = True retry = True
if not retry and r.status_code in accepted_response_codes: if not retry and r.status_code in accepted_response_codes:
@ -114,6 +119,7 @@ class Page:
cls.LOGGER.warning("to many tries. Aborting.") cls.LOGGER.warning("to many tries. Aborting.")
return None return None
cls.LOGGER.warning(f"payload: {json}")
return cls.post_request(url=url, json=json, accepted_response_codes=accepted_response_codes, trie=trie + 1) return cls.post_request(url=url, json=json, accepted_response_codes=accepted_response_codes, trie=trie + 1)
@classmethod @classmethod

View File

@ -79,7 +79,8 @@ class Musify(Page):
"Referer": "https://musify.club/" "Referer": "https://musify.club/"
} }
API_SESSION.proxies = shared.proxies API_SESSION.proxies = shared.proxies
TIMEOUT = 5 TIMEOUT = 7
POST_TIMEOUT = 10
TRIES = 5 TRIES = 5
HOST = "https://musify.club" HOST = "https://musify.club"

View File

@ -16,6 +16,10 @@ def fetch_artist():
source_list=[objects.Source(objects.SourcePages.MUSIFY, "https://musify.club/artist/ghost-bath-280348/")] source_list=[objects.Source(objects.SourcePages.MUSIFY, "https://musify.club/artist/ghost-bath-280348/")]
) )
artist = objects.Artist(
source_list=[objects.Source(objects.SourcePages.MUSIFY, "https://musify.club/artist/lana-del-rey-124788/releases")]
)
artist: objects.Artist = Musify.fetch_details(artist) artist: objects.Artist = Musify.fetch_details(artist)
print(artist.options) print(artist.options)
print(artist.main_album_collection[0].source_collection) print(artist.main_album_collection[0].source_collection)
@ -44,4 +48,4 @@ def fetch_album():
print(artist.id, artist.name) print(artist.id, artist.name)
if __name__ == "__main__": if __name__ == "__main__":
fetch_album() fetch_artist()