[Httplib2-discuss] Need to specify IP address for client socket (or provide custom HTTPConnection)
Status: Beta
Brought to you by:
jcgregorio
From: Simon W. <si...@si...> - 2007-07-30 10:41:53
|
Hi all, Had an interesting edge case come up today. I'm talking to a web service from a machine with two public-facing IP addresses. The web service in question is configured to only allow requests from one of them, so I need to be able to force my request to come from a specific IP address. After much research, it appears that the way to do this is to call the .bind() method on the socket object directly after it is created: self.sock = socket.socket(af, socktype, proto) self.sock.bind((required_ip_address, 0)) Using 0 for the port number tells the operating system to pick an available port. Unfortunately httplib2 doesn't currently provide a hook for substituting in a custom HTTPConnection implementation - it is hard coded to pick between HTTPConnectionWithTimeout and HTTPSConnectionWithTimeout. It would be really useful if there was a way to provide a custom HTTPConnection - in my case, I'd provide one that knows how to bind to a specified client socket IP address. Alternatively, adding direct support for my use case to the httplib2 library would be useful. Cheers, Simon |