From b1a8410376934bdc9414655a117c4398be7586e7 Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Tue, 4 Apr 2023 10:05:37 +0200 Subject: [PATCH] fixed bug with timeout --- src/music_kraken/pages/abstract.py | 8 +++++++- src/music_kraken/pages/musify.py | 3 ++- src/musify_search.py | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/music_kraken/pages/abstract.py b/src/music_kraken/pages/abstract.py index b2d3be3..d4f1190 100644 --- a/src/music_kraken/pages/abstract.py +++ b/src/music_kraken/pages/abstract.py @@ -62,6 +62,7 @@ class Page: API_SESSION: requests.Session = requests.Session() API_SESSION.proxies = shared.proxies TIMEOUT = 5 + POST_TIMEOUT = TIMEOUT TRIES = 5 LOGGER = LOGGER @@ -75,8 +76,10 @@ class Page: try: r = cls.API_SESSION.get(url, timeout=cls.TIMEOUT, stream=stream) except requests.exceptions.Timeout: + cls.LOGGER.warning(f"request timed out at \"{url}\": ({trie}-{cls.TRIES})") retry = True except requests.exceptions.ConnectionError: + cls.LOGGER.warning(f"couldn't connect to \"{url}\": ({trie}-{cls.TRIES})") retry = True if not retry and r.status_code in accepted_response_codes: @@ -97,10 +100,12 @@ class Page: requests.Response]: retry = False 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: + cls.LOGGER.warning(f"request timed out at \"{url}\": ({trie}-{cls.TRIES})") retry = True except requests.exceptions.ConnectionError: + cls.LOGGER.warning(f"couldn't connect to \"{url}\": ({trie}-{cls.TRIES})") retry = True if not retry and r.status_code in accepted_response_codes: @@ -114,6 +119,7 @@ class Page: cls.LOGGER.warning("to many tries. Aborting.") 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) @classmethod diff --git a/src/music_kraken/pages/musify.py b/src/music_kraken/pages/musify.py index 6c77e59..79b6715 100644 --- a/src/music_kraken/pages/musify.py +++ b/src/music_kraken/pages/musify.py @@ -79,7 +79,8 @@ class Musify(Page): "Referer": "https://musify.club/" } API_SESSION.proxies = shared.proxies - TIMEOUT = 5 + TIMEOUT = 7 + POST_TIMEOUT = 10 TRIES = 5 HOST = "https://musify.club" diff --git a/src/musify_search.py b/src/musify_search.py index 43c8965..ad79908 100644 --- a/src/musify_search.py +++ b/src/musify_search.py @@ -16,6 +16,10 @@ def fetch_artist(): 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) print(artist.options) print(artist.main_album_collection[0].source_collection) @@ -44,4 +48,4 @@ def fetch_album(): print(artist.id, artist.name) if __name__ == "__main__": - fetch_album() + fetch_artist()