Issues with running LabKey Python API

LabKey Trial Support
Issues with running LabKey Python API ambarish nag  2019-09-10 09:52
Status: Closed
 

Hi,
I am trying to write the .netrc for my MacOSX laptop.
I have started a LabKey trial site called ‘ANag_LabKey_Trial’ accessible at https://nrel-anag.trial.labkey.host

It is not clear to me what I should write in the line: machine <remote-instance-of-labkey-server>

When I use the following lines in the .netrc file:

machine nrel-anag.trial.labkey.host
login ambarish.nag@nrel.gov
password ********

I get the following error when I try to run the example case in
https://github.com/LabKey/labkey-api-python

Can you please help me fix these errors ?
Thanks,
Ambarish.

result = select_rows(server_context, schema, table)

Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
raise err
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/anaconda3/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/anaconda3/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/anaconda3/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/anaconda3/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/anaconda3/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
conn = self._new_conn()
File "/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x104777a90>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /labkey/ModuleAssayTest/login-whoami.api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x104777a90>: Failed to establish a new connection: [Errno 61] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/labkey/utils.py", line 93, in make_request
response = handle_response(self._session.get(csrf_url))
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /labkey/ModuleAssayTest/login-whoami.api (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x104777a90>: Failed to establish a new connection: [Errno 61] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.6/site-packages/labkey/query.py", line 286, in select_rows
return server_context.make_request(url, payload, timeout=timeout)
File "/anaconda3/lib/python3.6/site-packages/labkey/utils.py", line 98, in make_request
handle_request_exception(e, server_context=self)
File "/anaconda3/lib/python3.6/site-packages/labkey/utils.py", line 157, in handle_request_exception
raise ServerContextError(server_context, e)
labkey.exceptions.ServerContextError: 'Failed to connect to server. Ensure the server_context domain, context_path, and SSL are configured corr

 
 
Jon (LabKey DevOps) responded:  2019-09-11 21:25
Hello Ambarish,

Can you send us the actual Python code you're trying to run?

Based on the error, it looks like you're trying to access localhost:8080, which doesn't make sense if your .netrc file is configured to point to nrel-anag.trial.labkey.host

This leads me to believe that your code is the issue and not the Python API. If you can provide your Python code, we can confirm this.

Regards,

Jon