If an IP is not explicitly bound, which IP is used for the final source address is determined by routing. Explicitly binding the IP can indeed solve your problem, but it is not easy to let urllib2 or requests use the created (and bound) socket without changing the library code. The following is an article on how to make requests use the created socket: http://stackoverflow.com/ques...
For this kind of task, of course the priority is to find wheels
http://stackoverflow.com/ques...
https://github.com/aivarsk/sc...
If an IP is not explicitly bound, which IP is used for the final source address is determined by routing.
Explicitly binding the IP can indeed solve your problem, but it is not easy to let urllib2 or requests use the created (and bound) socket without changing the library code.
The following is an article on how to make requests use the created socket: http://stackoverflow.com/ques...