nglview
nglview copied to clipboard
show_pdbid: Connection refused
The documentation example fails. Minimal setup with uv using
uv init
uv add jupyter nglview
Code
import nglview as nv
w = nv.show_pdbid("3pqr")
Exception
---------------------------------------------------------------------------
ConnectionRefusedError Traceback (most recent call last)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:1344](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=1343), in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1343 try:
-> 1344 h.request(req.get_method(), req.selector, req.data, headers,
1345 encode_chunked=req.has_header('Transfer-encoding'))
1346 except OSError as err: # timeout error
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1336](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1335), in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
1335 """Send a complete request to the server."""
-> 1336 self._send_request(method, url, body, headers, encode_chunked)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1382](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1381), in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
1381 body = _encode(body, 'body')
-> 1382 self.endheaders(body, encode_chunked=encode_chunked)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1331](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1330), in HTTPConnection.endheaders(self, message_body, encode_chunked)
1330 raise CannotSendHeader()
-> 1331 self._send_output(message_body, encode_chunked=encode_chunked)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1091](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1090), in HTTPConnection._send_output(self, message_body, encode_chunked)
1090 del self._buffer[:]
-> 1091 self.send(msg)
1093 if message_body is not None:
1094
1095 # create a consistent interface to message_body
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1035](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1034), in HTTPConnection.send(self, data)
1034 if self.auto_open:
-> 1035 self.connect()
1036 else:
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1470](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1469), in HTTPSConnection.connect(self)
1468 "Connect to a host on a given (SSL) port."
-> 1470 super().connect()
1472 if self._tunnel_host:
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py:1001](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/http/client.py#line=1000), in HTTPConnection.connect(self)
1000 sys.audit("http.client.connect", self, self.host, self.port)
-> 1001 self.sock = self._create_connection(
1002 (self.host,self.port), self.timeout, self.source_address)
1003 # Might fail in OSs that don't implement TCP_NODELAY
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/socket.py:865](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/socket.py#line=864), in create_connection(address, timeout, source_address, all_errors)
864 if not all_errors:
--> 865 raise exceptions[0]
866 raise ExceptionGroup("create_connection failed", exceptions)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/socket.py:850](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/socket.py#line=849), in create_connection(address, timeout, source_address, all_errors)
849 sock.bind(source_address)
--> 850 sock.connect(sa)
851 # Break explicitly a reference cycle
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last)
Cell In[1], line 3
1 import nglview as nv
----> 3 w = nv.show_pdbid("3pqr")
File ~/temp/.venv/lib/python3.12/site-packages/nglview/show.py:53, in show_pdbid(pdbid, **kwargs)
44 '''Show PDB entry.
45
46 Examples
(...) 50 >>> w # doctest: +SKIP
51 '''
52 structure = PdbIdStructure(pdbid)
---> 53 return NGLWidget(structure, **kwargs)
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:189, in NGLWidget.__init__(self, structure, representations, parameters, **kwargs)
187 self._initialize_attributes(kwargs)
188 self._initialize_threads()
--> 189 self._initialize_components(structure, representations, parameters, kwargs)
190 self._initialize_layout(kwargs)
191 self._create_player()
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:247, in NGLWidget._initialize_components(self, structure, representations, parameters, kwargs)
245 else:
246 if structure is not None:
--> 247 self.add_structure(structure, **kwargs)
249 if representations:
250 # If initial representations are provided,
251 # we need to set defaultRepresentation to False
252 self.representations = representations
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:912, in NGLWidget.add_structure(self, structure, **kwargs)
910 if not isinstance(structure, Structure):
911 raise ValueError(f'{structure} is not an instance of Structure')
--> 912 self._load_data(structure, **kwargs)
913 self._ngl_component_ids.append(structure.id)
914 if self.n_components > 1:
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:1026, in NGLWidget._load_data(self, obj, **kwargs)
1024 self._load_data_from_url(obj, kwargs)
1025 else:
-> 1026 self._load_data_from_object(obj, kwargs)
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:1034, in NGLWidget._load_data_from_object(self, obj, kwargs)
1032 def _load_data_from_object(self, obj, kwargs):
1033 if hasattr(obj, 'get_structure_string'):
-> 1034 blob, ext, binary = self._get_structure_string_data(obj)
1035 else:
1036 blob, ext, binary, use_filename = self._get_file_manager_data(obj, kwargs)
File ~/temp/.venv/lib/python3.12/site-packages/nglview/widget.py:1048, in NGLWidget._get_structure_string_data(self, obj)
1047 def _get_structure_string_data(self, obj):
-> 1048 blob = obj.get_structure_string()
1049 ext = obj.ext
1050 binary = False
File ~/temp/.venv/lib/python3.12/site-packages/nglview/adaptor.py:130, in PdbIdStructure.get_structure_string(self)
128 def get_structure_string(self):
129 url = "http://www.rcsb.org/pdb/files/" + self.pdbid + ".cif"
--> 130 return urlopen(url).read().decode('utf-8')
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:215](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=214), in urlopen(url, data, timeout, cafile, capath, cadefault, context)
213 else:
214 opener = _opener
--> 215 return opener.open(url, data, timeout)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:521](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=520), in OpenerDirector.open(self, fullurl, data, timeout)
519 for processor in self.process_response.get(protocol, []):
520 meth = getattr(processor, meth_name)
--> 521 response = meth(req, response)
523 return response
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:630](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=629), in HTTPErrorProcessor.http_response(self, request, response)
627 # According to RFC 2616, "2xx" code indicates that the client's
628 # request was successfully received, understood, and accepted.
629 if not (200 <= code < 300):
--> 630 response = self.parent.error(
631 'http', request, response, code, msg, hdrs)
633 return response
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:553](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=552), in OpenerDirector.error(self, proto, *args)
551 http_err = 0
552 args = (dict, proto, meth_name) + args
--> 553 result = self._call_chain(*args)
554 if result:
555 return result
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:492](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=491), in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
490 for handler in handlers:
491 func = getattr(handler, meth_name)
--> 492 result = func(*args)
493 if result is not None:
494 return result
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:745](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=744), in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
742 fp.read()
743 fp.close()
--> 745 return self.parent.open(new, timeout=req.timeout)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:515](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=514), in OpenerDirector.open(self, fullurl, data, timeout)
512 req = meth(req)
514 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 515 response = self._open(req, data)
517 # post-process response
518 meth_name = protocol+"_response"
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:532](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=531), in OpenerDirector._open(self, req, data)
529 return result
531 protocol = req.type
--> 532 result = self._call_chain(self.handle_open, protocol, protocol +
533 '_open', req)
534 if result:
535 return result
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:492](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=491), in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
490 for handler in handlers:
491 func = getattr(handler, meth_name)
--> 492 result = func(*args)
493 if result is not None:
494 return result
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:1392](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=1391), in HTTPSHandler.https_open(self, req)
1391 def https_open(self, req):
-> 1392 return self.do_open(http.client.HTTPSConnection, req,
1393 context=self._context)
File [~/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py:1347](http://localhost:8888/home/michael/.local/share/uv/python/cpython-3.12.8-linux-x86_64-gnu/lib/python3.12/urllib/request.py#line=1346), in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
1344 h.request(req.get_method(), req.selector, req.data, headers,
1345 encode_chunked=req.has_header('Transfer-encoding'))
1346 except OSError as err: # timeout error
-> 1347 raise URLError(err)
1348 r = h.getresponse()
1349 except:
URLError: <urlopen error [Errno 111] Connection refused>
Thanks @mbackenkoehler for reporting. I am not sure what has changed recently since that has been working for years. um.
Most likely it's the PDB's move away from .pdb to .cif
Hi 👋 @hainm !
Most likely it's the PDB's move away from .pdb to .cif
Hi 👋 @hainm !
I see. Thanks.