navis-org / pymaid

Python library to interface with CATMAID servers. Fully interoperable with navis.
https://pymaid.readthedocs.io/en/latest/
GNU General Public License v3.0
23 stars 11 forks source link

requests.exceptions.ConnectionError: #215

Closed dadanhan closed 2 years ago

dadanhan commented 2 years ago

Hi, so I've just tried to use pymaid to do a simple check and see if I can extract data out of CATMAID...my code is the following

import pymaid
rm=pymaid.connect_catmaid()
neuron_list = pymaid.get_neuron(['1a PN'],remote_instance=rm)
print(neuron_list)

I've checked that the lines import pymaid and rm=pymaid.connect_catmaid() work. They indeed work. The error is given by the line neuron_list = pymaid.get_neuron(['1a PN'],remote_instance=rm) and it gives:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='myserverwebsite', port=443): Max retries exceeded with url: /catmaid/myserver/annotations/query-targets
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001AFB38A3580>: 
Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party 
did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

Could you please help solving this error? For clarification I'm using Windows and Python 3.8.10.

schlegelp commented 2 years ago

My first hunch is that you are using the wrong URL for your CATMAID server. The error message suggests that the server url is set to 'myserverwebsite' which can't be right.

connect_catmaid(), as you invoke it, uses the CATMAID_SERVER environment variable to initialise a connection. It does not check if the connection is working though. Hence you get your error when you first try to fetch data via pymaid.get_neuron.

dadanhan commented 2 years ago

So I've just edited the proper address to 'myserverwebsite'. The thing is I've had another lab member check my exact code with the exact same credentials and they seem to access the data fine. Could it be a Windows issue? The check was done on a non-Windows machine.

schlegelp commented 2 years ago

I'm a bit confused. Could you share the output of this:

rm = pymaid.connect_catmaid()
rm
dadanhan commented 2 years ago

INFO : Global CATMAID instance set. Caching is ON. (pymaid) CatmaidInstance at 2063042623952. Server: https://neurophyla.mrc-lmb.cam.ac.uk/catmaid/drosophila/l1/seymour Project: 1 Caching True (size limit 128; time limit None) Cache size: 0.0

schlegelp commented 2 years ago

Ah, that looks reasonable. Do you get an error if you run for example

ul = pymaid.get_user_list()
dadanhan commented 2 years ago

yes I get the error:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='neurophyla.mrc-lmb.cam.ac.uk', port=443): Max retries exceeded with url: /catmaid/drosophila/l1/seymour/user-list (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001BC37544C70>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))

which is exactly the same as before.

schlegelp commented 2 years ago

I guess the other thing you might want to check is if you can reach that server from your machine. In a terminal:

ping -c 5 neurophyla.mrc-lmb.cam.ac.uk

You should be seeing something like this:

64 bytes from 131.111.85.110: icmp_seq=2 ttl=50 time=23.726 ms
schlegelp commented 2 years ago

Also: I could be wrong but depending on whether you are connected via the LMB's wired network you might have use the internal name for this server.

@clbarnes @aschampion any thoughts?

dadanhan commented 2 years ago

Oh so I try

Test-NetConnection neurophyla.mrc-lmb.cam.ac.uk

because I'm running it on Windows Powershell and I get


ComputerName           : myserveraddress
RemoteAddress          : 111.111.111.someIP
InterfaceAlias         : Wi-Fi 2
SourceAddress          : 111.111.111.someIP
PingSucceeded          : False
PingReplyDetails (RTT) : 0 ms

So it indeed seems like I can't even access it from my machine rather than it being a problem in pymaid.

clbarnes commented 2 years ago

I said to Dan in a backchannel that I'm happy to blame Windows :laughing: but that's not exactly a solution. For reference I can use his credentials and the exact same code without issue from my computer outside the LMB network. Dan was using the LMB Guest network, which should behave as if it's outside.

Try neurophyla.lmb.internal just in case. Alternatively, there was a SO post which suggested that servers sometimes refuse to acknowledge requests if they're suspicious about the user-agent header, so we could try to change that and pretend to use a proper operating system.

dadanhan commented 2 years ago

@schlegelp and @clbarnes Thank you for all the help, it seems that this is an issue with my specific machine and not an issue with pymaid.