繁体   English   中英

Python 请求在“获取”方法上返回 401 代码

[英]Python Requests Returning 401 code on 'get' method

我正在研究一个网络爬虫 function,它将从内部(非公共)服务器中提取 HTML 数据。 我通过 VPN 和代理服务器建立了连接,因此当我 ping 任何公共站点时,我得到代码 200 没问题,但我们的内部返回 401。

这是我的代码:

http_str = f'http://username:password@proxy.yourorg.com:80'

proxyDict = {
    'http' : http_str, 
    'https' : https_str, 
    'ftp' : https_str
    }

html_text = requests.get(url, verify=True, proxies=proxyDict, auth=HTTPBasicAuth(user, pwd))

我尝试使用不同的证书链(有一个全新的问题列表)刷新我的 DNS 服务器。 我在 1.23 版上使用 urllib3,因为这似乎有助于解决 SSL 错误。 我考虑过使用请求 session 但我不确定这会改变什么。

此外,我们尝试访问的 url 不需要登录。我不知道为什么它会抛出 401 错误,但我认为身份验证是针对代理服务器的。 感谢任何帮助或想法,以及在这一点上的问题,我什至不知道要问什么来推动它。

编辑:proxyDict 有一个用户字符串,pwd 为每种类型传递它,https http fts 等。

要将 HTTP 基本身份验证与您的代理一起使用,请在任何代理配置条目中使用http://user:password@host/语法。 请参阅apidocs

import requests
proxyDict = {
    "http": "http://username:password@proxy.yourorg.com:80",
    "https": "http://username:password@proxy.yourorg.com:80"
}
url = 'http://myorg.com/example'
response = requests.get(url, proxies=proxyDict)

暂无
暂无

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

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