Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.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 使用urllib下载HTTPS页面,错误:14077438:SSL例程:SSL23\u GET\u SERVER\u HELLO:tlsv1警报内部错误_Python_Python 2.7_Ssl - Fatal编程技术网

Python 使用urllib下载HTTPS页面,错误:14077438:SSL例程:SSL23\u GET\u SERVER\u HELLO:tlsv1警报内部错误

Python 使用urllib下载HTTPS页面,错误:14077438:SSL例程:SSL23\u GET\u SERVER\u HELLO:tlsv1警报内部错误,python,python-2.7,ssl,Python,Python 2.7,Ssl,我正在使用最新的Kubuntu和python2.7.6。我尝试使用以下代码下载https页面: import urllib2 hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', 'Accept': 'text/html,application/xhtml+xml,applica

我正在使用最新的
Kubuntu
python2.7.6
。我尝试使用以下代码下载
https
页面:

import urllib2

hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'pl-PL,pl;q=0.8',
       'Connection': 'keep-alive'}

req = urllib2.Request(main_page_url, headers=hdr)

try:
    page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
    print e.fp.read()

content = page.read()
print content
然而,我得到了这样一个错误:

Traceback (most recent call last):
  File "test.py", line 33, in <module>
    page = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 1] _ssl.c:510: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error>
现在它下载页面

我正在使用最新的Kubuntu和Python 2.7.6

据我所知,最新的Kubuntu(15.10)使用了2.7.10。但假设您使用14.04 LTS中包含的2.7.6:

我也与facebook合作,所以这可能是页面问题。现在怎么办

那就要看现场了。此版本Python的典型问题是缺少对Python 2.7.9的支持。因为现在很多站点都需要SNI(就像所有使用Cloudflare免费SSL的站点一样),我想这就是问题所在


但是,也有其他的可能性,比如只有OpenSSL 1.0.2才能修复。或者只是缺少中间证书等。只有在您提供URL或根据此信息和分析自己分析情况的情况下,才能提供更多信息和可能的解决方法。

上述答案仅部分正确,您可以添加修复程序来解决此问题:

代码:

别无选择:

allow_unverified_content()

python 2.7.3的旧版本 使用

获取以下警告和异常:

You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
SSLError(SSLError(1, '_ssl.c:504: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error')

只需听从建议,访问


问题解决了。

您的脚本适用于Python 2.7.10和
https://facebook.com
。你尝试什么网址?这是发生在一个URL还是多个https上?@MartinVseticka:对我来说也适用于facebook,所以这可能是页面问题。现在怎么办?不,不是。但是如果不能够重现错误,就更难了,因此有人会回答你的问题的几率更低。无论如何,如果curl(或任何其他工具)也发生同样的情况,请尝试一下。我猜问题出在openssl方面而不是Python方面。是的,是Kubuntu 14.04,我的openssl是openssl 1.0.1f 2014年1月6日非常感谢。我使用了您发布的SSLLabs页面,并检查了该页面使用的TLS版本。结果是TLS1.2。我修改了代码,将编辑我的第一篇文章,并添加修改后的代码和解释。谢谢大家!@yak:因为Python 2.7.6也支持TLS1.2。在(K)Ubuntu14.04中,我的猜测是,升级到Python2.7.10只是修复了SNI问题,这就是它工作的原因。然而,它认为它是有效的。
allow_unverified_content()
requests.get(download_url, headers=headers, timeout=10, stream=True)
You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
SSLError(SSLError(1, '_ssl.c:504: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error')
pip install urllib3[secure]