nlpsandbox / nlpsandbox-client

Python client to interact with the NLP Sandbox
Apache License 2.0
3 stars 3 forks source link

The client does not throw an error when listing dataset from invalid host/path #193

Closed tschaffter closed 3 years ago

tschaffter commented 3 years ago

I would expect the following Python code to throw an error because the endpoint used is invalid (note the v2 portion of the host). The current behavior is that the code run without error.

from nlpsandboxclient import client

data_node_host = "http://localhost:8080/api/v2"

datasets = client.list_datasets(host=data_node_host)

for dataset in datasets:
  print("Dataset name: " + dataset.name)

Tagging @yy6linda as she is now using the client to pull predictions from data nodes (first local instance then Sage data node)

tschaffter commented 3 years ago

@thomasyu888 My bad. The issue stemmed from the fact that the following python code in an R notebook will not fully return.

from nlpsandboxclient import client

data_node_host = "http://fake-data-node:8080/api/v1"

datasets = client.list_datasets(host=data_node_host)

for dataset in datasets:
  print(dataset)

Terminal output (note the ... on the last line, which shows that the code block has not fully returned. Pressing ENTER in the terminal will show the print output):

>>> from nlpsandboxclient import client
>>> 
>>> data_node_host = "http://fake-data-node:8080/api/v1"
>>> 
>>> datasets = client.list_datasets(host=data_node_host)
>>> 
>>> for dataset in datasets:
...   print(dataset)
... 

@thomasyu888 @yy6linda The solution I found is to always add a blank line at the end of a Python code block:

from nlpsandboxclient import client

data_node_host = "http://fake-data-node:8080/api/v1"

datasets = client.list_datasets(host=data_node_host)

for dataset in datasets:
  print(dataset)
# blank line

EDIT: I added the string # blank line to represent the blank line, otherwise GitHub crops this blank line to make the code block smaller.

Back to the error issue, the error is then clearly printed in the terminal:

>>> from nlpsandboxclient import client
>>> 
>>> data_node_host = "http://fake-data-node:8080/api/v1"
>>> 
>>> datasets = client.list_datasets(host=data_node_host)
>>> 
>>> for dataset in datasets:
...   print(dataset)
... 
MaxRetryError: HTTPConnectionPool(host='fake-data-node', port=8080): Max retries exceeded with url: /api/v1/datasets?offset=0&limit=10 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fee2dff3df0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.