averbis / averbis-python-api

Conveniently access the REST API of Averbis products using Python
Apache License 2.0
12 stars 4 forks source link

URLs with special characters are not properly encoded #96

Closed DavidHuebner closed 2 years ago

DavidHuebner commented 2 years ago

Describe the bug URLs with special characters are not properly encoded, as an example our library would issue a request to http://localhost:8702/health-discovery/rest/experimental/textanalysis/projects/bug/documentSources/test/processes/PROCESS WITH #'. We observed this error when we wanted to list all processes and a process name included a specical character "#".

To Reproduce Steps to reproduce the behavior:

  1. Create a process name with a "#" character.
  2. Call project.list_processes()

Expected behavior We should add a urllib.parse.quote() to the def _build_url(self, endpoint): method.

Error message If applicable, add the error message to help explain your problem.

RequestException                          Traceback (most recent call last)
/tmp/ipykernel_5650/1642761360.py in <module>
      2 client = Client("ecstasy").ensure_available()
      3 project=client.get_project("whitespace_bug")
----> 4 document_collections = project.list_processes()

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in new_function(*args, **kwargs)
     67     @wraps(original_function)
     68     def new_function(*args, **kwargs):
---> 69         return original_function(*args, **kwargs)
     70 
     71     return new_function

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in list_processes(self)
   1156         """
   1157         # noinspection PyProtectedMember
-> 1158         return self.client._list_processes(self)
   1159 
   1160     @experimental_api

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in new_function(*args, **kwargs)
     67     @wraps(original_function)
     68     def new_function(*args, **kwargs):
---> 69         return original_function(*args, **kwargs)
     70 
     71     return new_function

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in _list_processes(self, project)
   2222         for item in response["payload"]:
   2223             document_collection = project.get_document_collection(item["documentSourceName"])
-> 2224             processes.append(document_collection.get_process(item["processName"]))
   2225         return processes
   2226 

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in new_function(*args, **kwargs)
     67     @wraps(original_function)
     68     def new_function(*args, **kwargs):
---> 69         return original_function(*args, **kwargs)
     70 
     71     return new_function

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in get_process(self, process_name)
    829         """
    830         # noinspection PyProtectedMember
--> 831         return self.project.client._get_process(self, process_name)
    832 
    833     @experimental_api

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in new_function(*args, **kwargs)
     67     @wraps(original_function)
     68     def new_function(*args, **kwargs):
---> 69         return original_function(*args, **kwargs)
     70 
     71     return new_function

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in _get_process(self, document_collection, process_name)
   2272         project = document_collection.project
   2273 
-> 2274         response = self.__request_with_json_response(
   2275             "get",
   2276             f"/experimental/textanalysis/projects/{project.name}/"

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in __request_with_json_response(self, method, endpoint, **kwargs)
   1389 
   1390         if not raw_response.ok:
-> 1391             self.__handle_error(raw_response)
   1392 
   1393         try:

~/.local/lib/python3.8/site-packages/averbis/core/_rest_client.py in __handle_error(raw_response)
   2460             pass
   2461 
-> 2462         raise RequestException(error_msg)
   2463 
   2464     @staticmethod

RequestException: 404 Server Error: 'Not Found' for url: 'http://ecstasy.averbis.intern:8702/health-discovery/rest/experimental/textanalysis/projects/whitespace_bug/documentSources/test/processes/PROCESS%20WITH%20'.
Endpoint error message is: 'In project 'whitespace_bug' is no text analysis for document collection 'test' with name 'PROCESS WITH '.'

Please complete the following information:

Additional context I will prepare a fix.