407使用python请求的代理响应

407使用python请求的代理响应,python,python-requests,Python,Python Requests,下面是我使用的代码。我正在使用最新的python。我使用python 2.7从下面的请求中得到407响应。 奇怪的是,我在请求中使用https而不是http时收到503响应 response = requests.get(query, proxies={'https': "https://username:password@104.247.XX.XX:80"}, headers=headers, timeout=30, allow_redirects=True) print response

下面是我使用的代码。我正在使用最新的python。我使用python 2.7从下面的请求中得到
407
响应。 奇怪的是,我在请求中使用
https
而不是
http
时收到503响应

response = requests.get(query, proxies={'https': "https://username:password@104.247.XX.XX:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
输出:响应[503]

response = requests.get(query, proxies={'http': "http://username:password@104.247.XX.XX:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
输出:响应[407]

response = requests.get(query, proxies={'http': "http://username:password@104.247.XX.XX:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
但同样的代码也适用于我的AmazonEC2实例。虽然我试图在本地机器上运行

import urllib2
import urllib
import portalocker
import cookielib
import requests

query = 'http://google.com/search?q=wtf&num=100&tbs=cdr:1,cd_min:2000,cd_max:2015&start=0&filter=0'
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Midori/0.4'}
response = requests.get(query, proxies={'http': "http://username:password@104.247.XX.XX:80"}, headers=headers, timeout=30, allow_redirects=True)
print response

状态代码可能会提供线索:

407 Proxy Authentication Required
503 Service Unavailable

这表明您的代理未针对https运行,并且您使用的代理的用户名/密码组合错误。请注意,您的本地计算机不太可能需要与ec2实例相同的代理。

嗯,用户名和密码组合是100%正确的。我从http获得407,从https获得503。我以前从https得到200。请看,没有解释的发布代码不是很有用
from requests.auth import HTTPProxyAuth

proxyDict = { 
          'http'  : '77.75.105.165', 
          'https' : '77.75.105.165'
        }
auth = HTTPProxyAuth('username', 'mypassword')

r = requests.get("http://www.google.com", proxies=proxyDict, auth=auth)