How to use Python to get URL and ignore 404 errors?

18 Replies, 1393 Views

For python get url ignore 404, you can also use the `retry` library to automatically retry failed requests. Sometimes 404s are temporary, so this can help.

Example:
```python
from retry import retry
import requests

@retry(tries=3, delay=2)
def fetch_url(url):
response = requests.get(url)
if response.status_code == 404:
print("404, skipping!")
else:
return response

fetch_url("http://example.com/404")
```
This adds some resilience to your script.

Messages In This Thread



Users browsing this thread: 1 Guest(s)