Python Requests, wie binde ich für jede Anfrage an eine andere Quell-IP? [Duplikat

Diese Frage hat hier bereits eine Antwort:

Anfragen, an eine IP binden 1 Antwort

Ich versuche, etwas Python zu lernen, und ich habe Probleme mit der Logik in dem, was ich testen möchte. Momentan ist mein Code so geschrieben, dass sich die Bindung an source_address nicht ändert, wenn der Prozess startet

import socket
import requests

real_create_conn = socket.create_connection

def set_src_addr(*args):
    address, timeout = args[0], args[1]
    source_address = ('201.X.X.1', 0)
    return real_create_conn(address, timeout, source_address)

socket.create_connection = set_src_addr

r = requests.get('http://www.mywebpage.com/main')
print r.status_code 
if r.status_code == 404
   print "Webpage Down!"

r = requests.get('http://www.mywebpage.com/blog')
print r.status_code 
if r.status_code == 204
   print "Error occured!"

Ich suche so etwas zu tun, wo

import socket
import requests


While 1: 

      #bind to source address 201.X.X.1
      #Send request to main webpage
      #print result
      time.sleep(300) # 5 minutes

      #bind to source address 201.X.X.12
      #Send request to blog webpage
      #print result
      time.sleep(300) # 5 minutes

Antworten auf die Frage(2)

Ihre Antwort auf die Frage