How do I properly use 'import requests python' for web scraping? or What's the best way to handle err

16 Replies, 1898 Views

Pro tip for error handling: use `requests.Session()` with retries.

```python
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

session = requests.Session()
retries = Retry(total=3, backoff_factor=1)
session.mount('http://', HTTPAdapter(max_retries=retries))
```

Now your session auto-retries on flakes. Lifesaver for sketchy APIs.

Messages In This Thread



Users browsing this thread: 1 Guest(s)