Creating an Adapter¶
When mounting an adapter, keep in mind that:
- for a given URL, requests will use the adapter associated to the longest matching prefix;
- session are created with adapters for the
https://prefixes (and thus adapters mounted on
httpswill never be used);
- requests only prepares URLs for http schemes (start with http and only contains letters, numbers, and the + and - signs).
paramswon’t work with the
mock://scheme, but will with
If you are not familiar with adapters, prefer the mocker approach (see Using the Mocker).
>>> import requests >>> import requests_mock >>> session = requests.Session() >>> adapter = requests_mock.Adapter() >>> session.mount('mock://', adapter)
At this point any requests made by the session to a URI starting with mock:// will be sent to our adapter.