Python请求私有代理身份验证不返回

时间:2019-05-29 00:00:48

标签: python authentication python-requests http-proxy proxy-authentication

我正在写一个抓取器,它将提取给定代理的信息。我正在将python请求与具有用户名和密码的专用代理一起使用,以访问“ https://ip8.com/”,该操作将提供有关代理的信息,并将抓取该信息。

现在,问题是我几乎尝试了所有操作,但请求未返回任何内容,实际上直到超时才返回。代理工作正常,因此没有问题。

我几乎尝试了所有方法。我也尝试过urllib3,但没有成功。

import requests
from requests.auth import HTTPProxyAuth

proxy_string = 'http://username:password@proxy:port'
s = requests.Session()
s.proxies = {"http": proxy_string , "https": proxy_string}
s.auth = HTTPProxyAuth("username","password")

r = s.get('https://ip8.com/') # OK
print(r.text)

我希望通过IP访问ip8.com的页面的html

1 个答案:

答案 0 :(得分:1)

import requests

proxy_string = 'http://username:password@proxy:port'
proxyDict = {"http": proxy_string , "https": proxy_string}

r = requests.get('https://ip8.com/', proxies=proxyDict) # OK
print(r.text)

以上方法应该有效