Python破坏了urllib2请求

时间:2015-09-22 18:06:06

标签: python python-2.7 urllib2 httplib

尝试运行程序时出现此错误:

Traceback (most recent call last):
  File "C:/Users/Adasli199/Desktop/Minetek-Testy-Stuff/tools/soldering-iron.py", line 400, in <module>
    MCVersionRegEx = cacheMCVersions()
  File "C:/Users/Adasli199/Desktop/Minetek-Testy-Stuff/tools/soldering-iron.py", line 141, in cacheMCVersions
    feeddata = opener.open(request).read()
  File "C:\Python27\lib\urllib2.py", line 404, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 422, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "C:\Python27\lib\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>

我正在尝试获取一些数据数据以帮助在代码的另一部分处理我的RegEx命令,这是它引用的函数抛出错误。

import httplib
import urllib2

def cacheMCVersions():
    request = urllib2.Request('https://mcversions.net/')
    request.add_header('User-Agent', 'SolderingIron/1.0 +http://tetrarch.co/') # identify ourselves so we don't get blocked
    opener = urllib2.build_opener()
    feeddata = opener.open(request).read()

在此之后还有一些正则表达式代码来解释数据但我觉得这就是解决问题所需的全部内容。在运行时,https://mcversions.net/已经启动并且仍然是我所知道的,这使得这个错误更加奇怪。

1 个答案:

答案 0 :(得分:0)

urllib在python 2.7.9上被破坏,在https次请求时被降低。

Install python 2.7.10 inside a virtual enviornment

它应该有效。您可能需要安装libssl-devopenssl,具体取决于您的Linux平台。