Changelog:
- 2024-07-15: updated to support recent HTTPX versions, based on @karpetrosyan's comment.
- 2021-01 (ish): initial version
An HTTPCore transport that uses urllib3 as the HTTP networking backend. (This was initially shipped with HTTPX.)
When used with HTTPX, this transport makes it easier to transition from Requests to HTTPX by keeping the same underlying HTTP networking layer.
Compatible / tested with: HTTPX 0.27.x
Note: not all urllib3
pool manager options are supported here — feel free to adapt this gist to your specific needs.
Using HTTPX:
import httpx
from urllib3_transport import URLLib3Transport
with httpx.Client(transport=URLLib3Transport()) as client:
response = client.get("https://example.org")
print(response)
If you want to pass a custom ssl_context
using the same options than HTTPX (verify
, cert
, trust_env
), use the httpx.create_ssl_context()
helper:
import httpx
from urllib3_transport import URLLib3Transport
ssl_context = httpx.create_ssl_context(verify="/tmp/client.pem")
with httpx.Client(transport=URLLib3Transport(ssl_context=ssl_context)) as client:
response = client.get("https://example.org")
print(response)
See also Changing the verification defaults in the HTTPX docs.
MIT License
Copyright (c) 2020 Florimond Manca
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
How can this be updated for the newest version of httpcore (v1.0.2)?