-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Option to Bind to a Local IP Address in httplib.py #48222
Comments
I updated httplib.py, python 2.4, to be able to bind to a specific IP conn = httplib.HTTPConnection('82.94.237.218', 80) will connect to '82.94.237.218' using one of the local IP addresses. For eth0 192.168.1.10 the outbound connection might use either eth0 or eth0:1. I'm not sure conn = httplib.HTTPConnection('82.94.237.218', 80, None, None, None,
'192.168.1.10') would make sure it used 192.168.1.10 not 192.168.1.11. I ran into this on a server that is contacted by an external legacy |
This is useful but as its a feature we won't be able to add it until Until then, the approach I suggest is to subclass httplib.HTTPConnection |
Sounds good. Let me know if there is anything I can do to help. Eldon On Thu, 2008-10-02 at 18:17 +0000, Gregory P. Smith wrote:
|
Did this ever happen? It seems like overkill in the non-Python sort of |
Since Gregory didn't update the ticket, it seems likely that it hasn't |
Just looking at the indicated file in the 2.6.4 release tarball, it does Unfortunately, I'm not in a position right now with my job to spend the Documentation should be relatively straightforward as well, since the Would have loved to have seen this in the 2.7/3.1 series, as it would |
I'm not sure why this is needed in httplib. Isn't it a matter of |
For my own case, I have a machine with 50 IP addresses set and I need to |
Why do you need to select manually between those 50 IP addresses? The problem I see with adding this to httplib is that it's not By the way, what I mean by routing is your OS' internal routing table # route -n The interface for each outbound route is part of the routing table. |
You are correct that more than just httplib may need this; however, it |
In case it helps, a guy recently reported the same issue for pyftpdlib: |
The patch files for Python 2.6 and a test file are in the attached tar httplib.HTTPConnection(host[, port[, strict[, timeout]]]) becomes httplib.HTTPConnection(host[, port[, strict[, timeout[, bindip]]]]) and httplib.HTTPSConnection(host[, port[, key_file[, cert_file[, strict[,
timeout]]]]]) becomes httplib.HTTPSConnection(host[, port[, key_file[, cert_file[, strict[,
timeout[, bindip]]]]]]) |
If you want the maximum chance for this to get applied, it would be best I imagine that writing the unittests so they will run on any machine |
yes its a real need and yes we should support this in the standard Thanks for the updated patch Eldon! |
trunk r77263 and r77264 add this feature, including documentation and tests. |
It seems to break at least one buildbot: ====================================================================== Traceback (most recent call last):
File "/var/lib/buildslave/trunk.murray-gentoo-wide/build/Lib/test/test_socket.py", line 120, in _tearDown
self.fail(msg)
AssertionError: Tuples differ: ('199.125.120.107', 40732) != ('127.0.0.1', 40732) First differing element 0:
---------------------------------------------------------------------- By the way, does the new "source_address" parameter have to be of the |
Ah, and I was even the one that suggested the bind to 127.0.0.1 strategy for the test :( My buildbots run in linux-vserver virtual hosts, and they way they handle localhost (127.0.0.1) is to alias it to the IP address assigned to the virthost (otherwise multiple virthosts opening ports on 127.0.0.1 would potentially conflict with each other). I'd consider this a bug in the virthost software (lack of feature?). Not sure what the best workaround is, but if all else fails we could put in some special case skip code. Would be good enough to have the test check that the returned IP address is *not* 0.0.0.0? Or perhaps issue a warning if the address is not 0.0.0.0 but isn't 127.0.0.1. |
I took the easy route and remove the test of the hostname all together. The fact that the source port was used is sufficient indication that the bind call was made. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: