Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for neuromorpho interface #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jakobtroidl
Copy link

This PR fixes errors in the navis neuromorpho interface. It seems like one of the URLs was deprecated, so I added the new, up-to-date one (http://cng.gmu.edu:8080/). Also, get_neuron previously threw an SSL error when requesting .swc files from the neuromorpho server. I added a workaround that pulls the files using pycurl, which works more reliably.

@schlegelp
Copy link
Collaborator

Thanks! This has been a thorn in my side for a while.

I had some local changes sitting around where I used resp = requests.get(url, verify=False) to work around the SSL certificate issue. Have you considered using that instead of pycurl? I'm a bit reluctant to add another dependency if not absolutely necessary.

I would also suggest being transparent about switching off verification. For e.g. you could have verification on by default and catch the SSL error adding a note that users can call the function with get_neuron(x, verify_ssl=False) to work around it but at their own risk.

Thoughts?

@jakobtroidl
Copy link
Author

I agree that resp = requests.get(url, verify=False) would be the more elegant solution. It was also my first choice, but it doesn't seem to resolve the issue (see minimal reproducer below). That's why I went with pycurl. Maybe I am doing something wrong...

import requests
url = "https://neuromorpho.org/dableFiles/nathans/CNG%20version/skin2-10x-7.CNG.swc"
response = requests.get(url, verify=False)

throws the following error

Traceback (most recent call last):
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    self._validate_conn(conn)
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1099, in _validate_conn
    conn.connect()
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/connection.py", line 653, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/connection.py", line 806, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 465, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
  File "/Users/jakobtroidl/Desktop/navis/venv/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 509, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 501, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1074, in _create
    self.do_handshake()
  File "/usr/local/Cellar/python@3.9/3.9.18/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1343, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1129)

Additionally, this seems to work without SSL errors but returns the wrong string.

import requests
url = "http://cng.gmu.edu:8080/dableFiles/nathans/CNG%20version/skin2-10x-7.CNG.swc"
response = requests.get(url)
print(response.text)

returns

<html><head><title>Apache Tomcat/7.0.54 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /dableFiles/nathans/CNG%20version/skin2-10x-7.CNG.swc</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/dableFiles/nathans/CNG%20version/skin2-10x-7.CNG.swc</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.54</h3></body></html>

I agree that the user should explicitly set disabling verification. I am happy to update my code after we decide which route to take.

@schlegelp
Copy link
Collaborator

FWIW I managed to find a workaround for requests:

import requests
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'DEFAULT:!DH'
url = "https://neuromorpho.org/dableFiles/nathans/CNG%20version/skin2-10x-7.CNG.swc"
response = requests.get(url, verify=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants