与 Python 的代理连接 [英] Proxy connection with Python

查看:55
本文介绍了与 Python 的代理连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从 python 连接到 URL.我试过了:urllib2、urllib3 和请求.这是我在所有情况下都遇到的相同问题.一旦我得到答案,我想他们三个都可以正常工作.

I have been attempting to connect to URLs from python. I have tried: urllib2, urlib3, and requests. It is the same issue that i run up against in all cases. Once I get the answer I imagine all three of them would work fine.

问题是通过代理连接.我已经输入了我们的代理信息,但没有任何乐趣.我收到 407 代码和错误消息,例如:HTTP 错误 407:需要代理身份验证(Forefront TMG 需要授权才能完成请求.对 Web 代理过滤器的访问被拒绝.)

The issue is connecting via proxy. I have entered our proxy information but am not getting any joy. I am getting 407 codes and error messages like: HTTP Error 407: Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )

但是,我可以使用另一个通过代理的其他应用程序进行连接,例如 git.当我运行 git config --get htpp.proxy 时,它返回的值和格式与我在 Python 中输入的值和格式相同,即

However, I can connect using another of other applications that go through the proxy, git for example. When I run git config --get htpp.proxy it returns the same values and format that I am entering in Python namely

http://username:password@proxy:8080

请求中的代码示例是

import requests
proxy = {"http": "http://username:password@proxy:8080"}
url = 'http://example.org'
r = requests.get(url,  proxies=proxy)
print r.status_code

感谢您的时间

推荐答案

我通过安装 CNTLM 解决了我的问题.设置和配置完成后,我会设置 HTTP_PROXY 等.

I have solved my issue by installing CNTLM. Once this is setup and configured I set the HTTP_PROXY etc.

这篇关于与 Python 的代理连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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