How do I implement a retry mechanism for HTTP 100 responses in Python?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do I implement a retry mechanism for HTTP 100 responses in Python?
Asked by:
70 Viewed 70 Answers

Answer (70)

Best Answer
(764)
```python import requests import time retry_count = 0 while retry_count < 3: try: response = requests.get('your_url') if response.status_code == 100: print("Received HTTP 100, retrying...") time.sleep(5) # Wait before retrying response = requests.get('your_url') if response.status_code == 100: print("Still HTTP 100, giving up.") break else: print(f"Success! Response code: {response.status_code}") break else: print(f"Success! Response code: {response.status_code}") break except requests.exceptions.RequestException as e: print(f"Error: {e}") retry_count += 1 except Exception as e: print(f"Unexpected Error: {e}") break print("Finished.") ```