Python/requests: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
Line 14: Line 14:
</source>
</source>


== Hierarchy ==
== Hierarchy of Exceptions ==
<quickgv name="requests_exp">
<quickgv name="requests_exp">
A [label="IOError"];
A [label="IOError"];

Revision as of 04:19, 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)

Hierarchy of Exceptions