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. |
Answered by
karpetrosyan
May 24, 2023
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) |
5 replies
|
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) |
0 replies
Answer selected by
lovelydinosaur
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since #2716 has been merged, hopefully this api will provide the answer to your question beginning with version 0.24.2.