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

18 Replies, 1124 Views

Yo, for python get url ignore 404, you can also use the `requests` library with `status_code` checks. Instead of raising an exception, just check if the status code is 404 and move on.

Like this:
```python
import requests

url = "http://example.com/nope"
response = requests.get(url)
if response.status_code == 404:
print("404, but we're chill. Skipping!")
else:
print("All good, proceed!")
```
This is super simple and avoids try-except if you don’t wanna deal with that.

Messages In This Thread



Users browsing this thread: 1 Guest(s)