阿小信大人的头像
Where there is a Python, there is a way. 阿小信大人

Redhat backport Python2.7.5的一个bug2016-03-02 15:54

Redhat新机器上在用到一个Python第三方库suds时报错:

File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/client.py", line 637, in send
    reply = transport.send(request)
File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/transport/https.py", line 64, in send
    return  HttpTransport.send(self, request)
File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/transport/http.py", line 77, in send
    fp = self.u2open(u2request)
File "/srv/ves/talaris.courier/.venv/lib/python2.7/site-packages/suds/transport/http.py", line 118, in u2open
    return url.open(u2request, timeout=tm)
File "/usr/lib64/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
File "/usr/lib64/python2.7/urllib2.py", line 449, in _open
    '_open', req)
File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 1258, in https_open
    context=self._context, check_hostname=self._check_hostname)
File "/usr/lib64/python2.7/urllib2.py", line 1211, in do_open
    h.request(req.get_method(), req.get_selector(), req.data, headers)
File "/usr/lib64/python2.7/httplib.py", line 979, in request
    self._send_request(method, url, body, headers)
File "/usr/lib64/python2.7/httplib.py", line 1013, in _send_request
    self.endheaders(body)
File "/usr/lib64/python2.7/httplib.py", line 975, in endheaders
    self._send_output(message_body)
File "/usr/lib64/python2.7/httplib.py", line 835, in _send_output
    self.send(msg)
File "/usr/lib64/python2.7/httplib.py", line 797, in send
    self.connect()
File "/usr/lib64/python2.7/httplib.py", line 1198, in connect
    server_hostname=sni_hostname)
File "/usr/lib64/python2.7/ssl.py", line 350, in wrap_socket
    _context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'

一路跟进去发现是在用urllib2发起https请求的时候报这个错,对比老的机器发现python版本不一样,虽然同是2.7.5但是小版本不同,

新加的是python.x86_64.0.2.7.5-34.el7,老的是python.x86_64.0.2.7.5-16.el7.

在2.7.5-34上

In [1]: import urllib2

In [2]: urllib2.urlopen('https://www.baidu.com')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/srv/ves/talaris.courier/.venv/bin/ves in <module>()
----> 1 urllib2.urlopen('https://www.baidu.com')

/usr/lib64/python2.7/urllib2.pyc in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    152     else:
    153         opener = _opener
--> 154     return opener.open(url, data, timeout)
    155
    156 def install_opener(opener):

/usr/lib64/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
    429             req = meth(req)
    430
--> 431         response = self._open(req, data)
    432
    433         # post-process response

/usr/lib64/python2.7/urllib2.pyc in _open(self, req, data)
    447         protocol = req.get_type()
    448         result = self._call_chain(self.handle_open, protocol, protocol +
--> 449                                   '_open', req)
    450         if result:
    451             return result

/usr/lib64/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, *args)
    407             func = getattr(handler, meth_name)
    408
--> 409             result = func(*args)
    410             if result is not None:
    411                 return result

/usr/lib64/python2.7/urllib2.pyc in https_open(self, req)
1256         def https_open(self, req):
1257             return self.do_open(httplib.HTTPSConnection, req,
-> 1258                 context=self._context, check_hostname=self._check_hostname)
1259
1260         https_request = AbstractHTTPHandler.do_request_

/usr/lib64/python2.7/urllib2.pyc in do_open(self, http_class, req, **http_conn_args)
1209
1210         try:
-> 1211             h.request(req.get_method(), req.get_selector(), req.data, headers)
1212         except socket.error, err: # XXX what error?
1213             h.close()

/usr/lib64/python2.7/httplib.pyc in request(self, method, url, body, headers)
    977     def request(self, method, url, body=None, headers={}):
    978         """Send a complete request to the server."""
--> 979         self._send_request(method, url, body, headers)
    980
    981     def _set_content_length(self, body):

/usr/lib64/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
1011         for hdr, value in headers.iteritems():
1012             self.putheader(hdr, value)
-> 1013         self.endheaders(body)
1014
1015     def getresponse(self, buffering=False):

/usr/lib64/python2.7/httplib.pyc in endheaders(self, message_body)
    973         else:
    974             raise CannotSendHeader()
--> 975         self._send_output(message_body)
    976
    977     def request(self, method, url, body=None, headers={}):

/usr/lib64/python2.7/httplib.pyc in _send_output(self, message_body)
    833             msg += message_body
    834             message_body = None
--> 835         self.send(msg)
    836         if message_body is not None:
    837             #message_body was not a string (i.e. it is a file) and

/usr/lib64/python2.7/httplib.pyc in send(self, data)
    795         if self.sock is None:
    796             if self.auto_open:
--> 797                 self.connect()
    798             else:
    799                 raise NotConnected()

/usr/lib64/python2.7/httplib.pyc in connect(self)
1196
1197             self.sock = self._context.wrap_socket(self.sock,
-> 1198                                                   server_hostname=sni_hostname)
1199             if not self._context.check_hostname and self._check_hostname:
1200                 try:

/usr/lib64/python2.7/ssl.pyc in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    348                          suppress_ragged_eofs=suppress_ragged_eofs,
    349                          server_hostname=server_hostname,
--> 350                          _context=self)
    351
    352     def set_npn_protocols(self, npn_protocols):

TypeError: __init__() got an unexpected keyword argument 'server_hostname'

In [3]:

在2.7.5-16上一切正常,谷歌一下发现应该是Redhat操作系统在对2.7.5做2.7.9以后的backport的时候出了问题, 基本上和这个issue是一个情况:https://github.com/gevent/gevent/issues/702

最后是通过降级到2.7.5-16解决的。

如果您觉得从我的分享中得到了帮助,并且希望我的博客持续发展下去,请点击支付宝捐赠,谢谢!

若非特别声明,文章均为阿小信的个人笔记,转载请注明出处。文章如有侵权内容,请联系我,我会及时删除。

#Python#  
分享到:
阅读[1385] 评论[0]

你可能也感兴趣的文章推荐

本文最近访客

发表评论