deeenes
deeenes

Reputation: 4586

Module chembl_webresource_client.new_client fails because broken ssl in urllib3 under python 2.7.9

The module chembl_webresource_client.new_client (version 0.8.5) available from pypi, is a client for accessing the new web service API of the ChEMBL database. It uses urllib3 which is broken for a while in python 2.7.9, because of the missing sslwrap in the built in ssl module. If I try to import the module:

from chembl_webresource_client.new_client import new_client

The stack trace looks like this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/chembl_webresource_client/new_client.py", line 63, in <module>
    new_client = client_from_url(Settings.Instance().NEW_CLIENT_URL + '/spore')
  File "/usr/lib/python2.7/site-packages/chembl_webresource_client/new_client.py", line 27, in client_from_url
    res = requests.get(url)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 65, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/api.py", line 49, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 461, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 762, in _validate_conn
    conn.connect()
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/usr/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py", line 256, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python2.7/ssl.py", line 350, in wrap_socket
    _context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'

Finally I could resolve this problem, I will post the solution below.

Upvotes: 0

Views: 763

Answers (1)

deeenes
deeenes

Reputation: 4586

First, I tried to use the patch from this thread, without success. Finally from this answer I found out, that installing pyopenssl, ndg-httpsclient and pyasn1 is necessary to resolve the problem.

pip2 install pyopenssl
pip2 install ndg-httpsclient
pip2 install pyasn1

And the ChEMBL module can be imported:

from chembl_webresource_client.new_client import new_client

Upvotes: 1

Related Questions