Scrapy:如何设置 HTTP 代理以连接到 HTTPS 网站(HTTP 有效)? [英] Scrapy: How do I set an HTTP proxy to connect to HTTPS websites (HTTP works)?
本文介绍了Scrapy:如何设置 HTTP 代理以连接到 HTTPS 网站(HTTP 有效)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用中间件来启用这样的代理:
I'm using a middleware to enable a proxy like this:
我在 settings.py 中有这个
I have this in settings.py
HTTP_PROXY='127.0.0.1:8080'
这是我的中间件
from mybot.settings import HTTP_PROXY
class ProxyMiddleware(object):
def process_request(self, request, spider):
request.meta['proxy'] = 'http://%s' % HTTP_PROXY
它适用于 HTTP 站点,但不适用于 HTTPS.我究竟做错了什么?我已经使用 curl 测试了代理,它可以毫无问题地连接到 HTTPS.
It works fine for HTTP sites but not for HTTPS. What am I doing wrong? I have tested the proxy using curl and it can connect to HTTPS without a problem.
这是错误:
[<twisted.python.failure.Failure <class 'twisted.internet.error.ConnectionDone'>>]
推荐答案
您需要同时为 http 和 https 启用代理.例如在 Windows 中,您可以直接从 shell 中执行此操作,例如
You need to enable proxy for http and https both. For example in Windows, you can do it directly from shell like
set http_proxy = 127.0.0.1:8080
set https_proxy = 127.0.0.1:8080
这篇关于Scrapy:如何设置 HTTP 代理以连接到 HTTPS 网站(HTTP 有效)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文