Python 请求 API 使用代理进行 https 请求获取 407 需要代理身份验证 [英] Python requests API using proxy for https request get 407 Proxy Authentication Required

查看:393
本文介绍了Python 请求 API 使用代理进行 https 请求获取 407 需要代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使用我的公司代理来发出 https 请求.

I've been struggling with my company proxy to make an https request.

import requests
from requests.auth import HTTPProxyAuth

proxy_string = 'http://user:password@url_proxt:port_proxy'

s = requests.Session()
s.proxies = {"http": proxy_string , "https": proxy_string}
s.auth = HTTPProxyAuth(user,password)

r = s.get('http://www.google.com') # OK
print(r.text)
r = s.get('https://www.google.com',proxies={"http": proxy_string , "https": proxy_string}) #OK
print(r.text)
r = s.get('https://www.google.com') # KO
print(r.text)

当 KO 时,我有以下异常:

When KO, I have the following exception :

HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',)))

我在网上查看,但没有发现有人对 HTTPS 有此特定问题.

I looked online but didn't find someone having this specific issue with HTTPS.

感谢您的时间

推荐答案

感谢 Lukasa 的大力帮助,我解决了我的问题.

Thanks to the amazing help of Lukasa, I solved my issue.

请在此处查看有关修复的讨论或设置:

session.trust_env=False

这篇关于Python 请求 API 使用代理进行 https 请求获取 407 需要代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆