繁体   English   中英

407使用python请求从代理响应

[英]407 response from proxy using 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

输出:回应[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]

但是同样的代码正在我的amazon ec2实例上运行。 虽然我想在本地机器上运行。

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
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)

状态代码可能会给出一个线索:

407 Proxy Authentication Required
503 Service Unavailable

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM