Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t使用urlib2通过代理发送HTTPS请求_Python_Https_Openssl_Urllib2 - Fatal编程技术网

Python Can';t使用urlib2通过代理发送HTTPS请求

Python Can';t使用urlib2通过代理发送HTTPS请求,python,https,openssl,urllib2,Python,Https,Openssl,Urllib2,我试图创建一个Python脚本,通过代理发送HTTPS请求(确切地说是Burp),但它一直失败 ssl.CertificateError: hostname 'example.com:443' doesn't match u'example.com' 以下是我的代码的缩写版本: proxy = urllib2.ProxyHandler({'https': '127.0.0.1:8080'}) opener = urllib2.build_opener(proxy) opener.addhea

我试图创建一个Python脚本,通过代理发送HTTPS请求(确切地说是Burp),但它一直失败

ssl.CertificateError: hostname 'example.com:443' doesn't match u'example.com'
以下是我的代码的缩写版本:

proxy = urllib2.ProxyHandler({'https': '127.0.0.1:8080'})
opener = urllib2.build_opener(proxy)

opener.addheaders = [ ("Host", "example.com"),
                    ...
                    ]
urllib2.install_opener(opener)  
try:
    req = opener.open( 'https://example.com/service', 'data' ).read()
except urllib2.URLError, e:
    print e

因此,Python似乎认为Python(
ssl.CertificateError
是Python错误,而不是OpenSSL错误)的端口或其中一个地址使用Unicode存在问题。对我来说这两个都没有意义。有什么建议吗?

试试这段代码。我用
打嗝

test.py

import urllib2

opener = urllib2.build_opener(
                urllib2.HTTPHandler(),
                urllib2.HTTPSHandler(),
                urllib2.ProxyHandler({'https': 'localhost:8080'}))
urllib2.install_opener(opener)
print opener.open( 'https://example.com', 'data' ).read()
打嗝配置


演示

没有。同样的结果。不过谢谢你的努力。奇怪的是,它实际上是通过打嗝发送的,并收到一个响应,所以证书已经被处理了。我无法理解为什么会出现问题。请将服务器正在使用的证书发布到
127.0.0.1:8080
。此外,8443通常用作备用HTTPS端口。