pythontwisted框架HttpClient访问代理吗?
我需要使用访问网页
twisted.web.client.getPage()
或类似的方法从已知地址(即:www.google.com)下载网页,问题是:我位于代理服务器后面,我找不到任何有关如何下载网页的说明配置扭曲或工厂来使用我的代理,有什么想法吗?
请记住,我必须指定用户、密码、主机和端口。 在我的 Linux 机器上,我将 http_proxy
和 https_proxy
设置为 http://user:pwd@ip:port
提前谢谢。
I need to access a webpage using
twisted.web.client.getPage()
or a similar method to download a webpage from a known address (ie:www.google.com), the problem is: I am behind a proxy server and I couldn't find anywhere explanations on how to configure twisted or factories to use my proxy, any ideas?
Bear in mind I have to specify user, password, host and port.
On my linux machine I setup http_proxy
and https_proxy
to http://user:pwd@ip:port
Thankyou in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了让 nosklo 的解决方案发挥作用,您需要为“401”创建另一个处理程序,以指示需要身份验证。尝试这样的操作
这将提示操作员在命令行提供信息,或者您可以以您选择的其他方式提供用户名和密码。确保这是作为 Errback 添加的第一个处理程序,然后再添加任何其他处理程序(甚至是 Callback)。这还需要更多的进口; 'base64'、'getpass' 和 'error' 与命令行提示一起使用。
To get nosklo's solution to work you will need to create another handler for the '401' that indicates that authentication is required. Try something like this
This will prompt the operator to supply the information at the command line, or you couple could supply the username and password in another way of your choosing. Make sure this is the first handler added as an Errback, before any other handlers are added even the Callback. This also requires a few more imports; 'base64', 'getpass', and 'error' to work with the command line prompts.
我必须使用基本身份验证执行类似的操作,因为身份验证请求的示例代码在这里不起作用,但可以使用的版本是:
I had to do something similar using base auth, since the example code for the auth request did not work here is a version that works:
我们选择使用
http_proxy
环境变量。我们遇到了重定向问题,重定向并不总是被接收,或者更确切地说是以正确的方式被接收。也就是说,nosklo
的回应确实很有帮助!We chose to use the
http_proxy
environment variable. We were having trouble with redirections not always getting picked up, or rather getting picked up in the right way. That said,nosklo
's response really helped!