Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在请求中设置接口IP?_Python_Python 2.7 - Fatal编程技术网

Python 如何在请求中设置接口IP?

Python 如何在请求中设置接口IP?,python,python-2.7,Python,Python 2.7,我的服务器有3个IP,如何在python请求中设置接口IP 我当前的脚本: import requests headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0', 'Accept-Language' : 'en-en,en;q=0.8,en-us;q=0.5,en;q=0.3',

我的服务器有3个IP,如何在python请求中设置接口IP

我当前的脚本:

import requests

headers = {
               'User-Agent'  :  'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0',
               'Accept-Language'  :  'en-en,en;q=0.8,en-us;q=0.5,en;q=0.3',
               'Connection'  :  'keep-alive',
               'RequestTarget': 'AJAXService',
               'Origin'      :  'http://m.site.com',
               'Content-Type': 'application/x-www-form-urlencoded',
               'Accept': '*/*',
               'Referer': 'http://m.site.com/'
               }

cookies = {
    'ASP.NET_SessionId': 'py5beylwcovqwmikg0tputgn',
    'lng': '4'
    }

r = requests.get("http://httpbin.org/get", cookies=cookies, headers=headers)

print r.text
但是这个脚本只使用默认的IP,但是我每次都需要更改它