How to send http request through specific network interface? #2635
-
I have two network interfaces and both with internet access. Let's say my interfaces are eth0 and ETH999. I need specific requests to go through ETH999 interface and eth0 is the default interface in my server.
so how to do the same on Httpx? thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi there. Is this what you're looking for?... https://www.python-httpx.org/advanced/#custom-transports
>>> import httpx
>>> transport = httpx.HTTPTransport(local_address="0.0.0.0")
>>> client = httpx.Client(transport=transport) |
Beta Was this translation helpful? Give feedback.
-
Since #2716 has been merged, hopefully this api will provide the answer to your question beginning with version 0.24.2. >>> import httpx
>>> socket_options = [(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"ETH999")]
>>> transport = httpx.HTTPTransport(socket_options=socket_options)
>>> client = httpx.Client(transport=transport) |
Beta Was this translation helpful? Give feedback.
Since #2716 has been merged, hopefully this api will provide the answer to your question beginning with version 0.24.2.