Reputation:
I am writing a url fetcher. When I send a request like:
import requests
response = requests.get("http://example.com")
Sometimes an error like this occurs:
ConnectionError: ('Connection aborted.', BadStatusLine(""''''"))
But when I try one more time, it fixes. So I would like to send one more time when such an error occurs again. How can I do that? Thank you in advance!
Upvotes: 1
Views: 231
Reputation: 9879
Repeat the request again when the exception is raised.
import requests
url = "http://example.com"
try:
response = requests.get(url)
except requests.exception.ConnectionError:
response = requests.get(url)
Upvotes: 1