Skip to content

Instantly share code, notes, and snippets.

@DxDiagDx
Created June 28, 2022 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DxDiagDx/03e7664b4b6895d5ed2738aba95df857 to your computer and use it in GitHub Desktop.
Save DxDiagDx/03e7664b4b6895d5ed2738aba95df857 to your computer and use it in GitHub Desktop.
Woo API — get_response: отправляем повторный запрос при неудачной попытке
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