diff --git a/docs/user/quickstart.rst b/docs/user/quickstart.rst index 3755d26239..85ade5c67e 100644 --- a/docs/user/quickstart.rst +++ b/docs/user/quickstart.rst @@ -271,9 +271,12 @@ use the same key:: }, ... } - >>> r1.text == r2.text + >>> r1.json()['form'] == r2.json()['form'] True +The complete response text may differ between requests (for example, due to +headers added by ``httpbin``), but the form payload is equivalent. + There are times that you may want to send data that is not form-encoded. If you pass in a ``string`` instead of a ``dict``, that data will be posted directly. @@ -399,6 +402,20 @@ But, since our ``status_code`` for ``r`` was ``200``, when we call >>> r.raise_for_status() None +For complete status/error handling in one example:: + + >>> import requests + >>> from requests.exceptions import HTTPError + >>> try: + ... response = requests.get('https://api.github.com') + ... response.raise_for_status() + ... except HTTPError as http_err: + ... print(f'HTTP error occurred: {http_err}') + ... except Exception as err: + ... print(f'Other error occurred: {err}') + ... else: + ... print('Success!') + All is well.