Created
June 28, 2022 10:01
-
-
Save DxDiagDx/03e7664b4b6895d5ed2738aba95df857 to your computer and use it in GitHub Desktop.
Woo API — get_response: отправляем повторный запрос при неудачной попытке
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_response(metod, endpoint=None, params=None, data=None): | |
response = None | |
for attemp in range(1, 6): | |
try: | |
if 'get' == metod.lower(): | |
response = wcapi.get(endpoint=endpoint, params=params) | |
if 'post' == metod.lower(): | |
response = wcapi.post(endpoint=endpoint, params=params, data=data) | |
except Exception as error: | |
print('Ошибка:', error) | |
print('Не удалось получить данные. Пытаемся снова') | |
time.sleep(2) | |
continue | |
if response: | |
break | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment