我刚刚为 python 应用程序安装了 Proximo heroku 插件。我加载了一个 shell 并进行了测试,发现 HTTP 地址有效,但 HTTPS 地址无效。 HTTP 地址显示在 Proximo 日志中,HTTPS 地址超时,日志中没有留下任何内容。
我使用以下代码进行了测试:
import urllib2, urllib
from django.conf import settings
proxy = urllib2.ProxyHandler(settings.PROXIES_DICT)
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)
urllib2.urlopen("http://google.com").read() # works fine
urllib2.urlopen("https://google.com").read() # times out
我应该提到 PROXIES_DICT 看起来像这样(密码已替换):
>>> pprint(settings.PROXIES_DICT)
{'http': 'http://proxy:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4131203232362e33250131332e39386c74756c7372746c76736c78776f31332e39282c2e6f282e" rel="noreferrer noopener nofollow">[email protected]</a>',
'https': 'http://proxy:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5e4f5d5d59415c4a6e5e5c415657031b1a031c1d1b03191c031718005e5c4156474341004741" rel="noreferrer noopener nofollow">[email protected]</a>'}
我还应该提到超时异常如下所示:
URLError: <urlopen error [Errno 60] Operation timed out>
我不确定我做错了什么。有人可以帮忙吗?
最佳答案
此代码尝试使用 HTTP 连接到 Proximo 代理,但端口为 443。尝试以下设置:
{'http': 'http://proxy:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1161706262667e63755161637e69683c24253c2322243c26233c28273f61637e69787c7e3f787e" rel="noreferrer noopener nofollow">[email protected]</a>',
'https': 'http://proxy:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8d8c9dbdbdfc7dacce8d8dac7d0d1859d9c859a9b9d859f9a85919e86d8dac7d0c1c5c786c1c7" rel="noreferrer noopener nofollow">[email protected]</a>:80'}
您知道 Proximo 不监听 HTTPS,因此从您的应用程序到代理的连接不会加密?
关于heroku - Proximo heroku 插件在 https 请求上超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16284804/