Python/requests: Difference between revisions
< Python
Jump to navigation
Jump to search
| Line 18: | Line 18: | ||
A [label="IOError"]; | A [label="IOError"]; | ||
B [label="RequestException"]; | B [label="RequestException"]; | ||
C1 [label="HttpError"]; | |||
C2 [label="ConnectionError"]; | |||
A -> B; | A -> B -> {C1 C2}; | ||
</quickgv> | </quickgv> | ||
Revision as of 04:11, 14 October 2019
Standard Usage
import requests
from requests.exceptions import ConnectionError
try:
resp = requests.get('https://duckduckgo.com/')
if resp.status_code == 200:
print(resp.text)
else:
print(resp.status_code)
except ConnectionError as ex:
print(ex)