Repository navigation
Closed
Labels
backendThis relates to the backend bugs or implementationThis relates to the backend bugs or implementation
Description
(Created from email ticket)
Description
When requesting data products during an interval when no data exists, the onc package raises a TypeError: sting indices must be integers
Expected Behavior
Either raise a more meaningful error, return a request dictionary with a null id
Actual behavior/MWE:
MWE:
from onc.onc import ONC
onc = ONC(<your token>)
request = onc.requestDataProduct(
filters={
"dataProductCode": "AD",
"extension": "wav",
"dateFrom": "2016-01-01T12:00:00.000Z",
"dateTo": "2016-01-01T12:01:00.000Z",
"deviceCode": "ICLISTENHF1251",
"dpo_hydrophoneDataDiversionMode": "OD",
"dpo_audioDownsample": -1,
}
)Raises:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/jmsh/github/tehom/env/lib/python3.7/site-packages/onc/onc.py", line 99, in requestDataProduct
return self.delivery.requestDataProduct(filters)
File "/home/jmsh/github/tehom/env/lib/python3.7/site-packages/onc/modules/_OncDelivery.py", line 62, in requestDataProduct
self._printProductRequest(response)
File "/home/jmsh/github/tehom/env/lib/python3.7/site-packages/onc/modules/_OncDelivery.py", line 235, in _printProductRequest
print('Request Id: {:d}'.format(response['dpRequestId']))
TypeError: string indices must be integers
Discussion:
The error results because
_OncDelivery.requestDataProduct()dispatches toOncService.doRequest()(link)_OncService.doRequest()gets a HTTP200 response with json content that is just a string, in violation of the API (link)- That request gets passed back to
_OncDelivery.requestDataProduct()... - which is then passed on to
_OncService._printProductRequest() _OncService._printProductRequest()then queriesresponse['dpRequestId'], butresponseis a string, raising theTypeError(link)
The API is clear that the server should be returning HTTP 400 with an error code of 33 and the message "No data found for data search with given parameters". If it's easier to fix the client library rather than the server, I could PR a stopgap where doRequest checks the json response for a top-level string rather than a dict, and raises a ValueError appropriately. Thoughts?
Metadata
Metadata
Assignees
Labels
backendThis relates to the backend bugs or implementationThis relates to the backend bugs or implementation
Type
Projects
- StatusShow more project fieldsDone
Activity
ENH: Workaround bugs in ONC server
kan-fu commentedon Nov 22, 2023
The bug has been fixed in the backend. Could you double check to see if the issue could be closed?
Jacob-Stevens-Haas commentedon Nov 30, 2023
It works and causes the exception in the proper place. However, I still think the error should be a
ValueError(as noted in (this SO post)[https://stackoverflow.com/a/30855949/534674]. theelseexception could just useResponse.raise_for_status()kan-fu commentedon Nov 30, 2023
Yeah, I agree. Pylint gave me a lot of broad-exception-caught warning. These exceptions could be narrowed down to give a more meaningful error.
I am not experienced in dealing with Exceptions. Do you want to create a new issue for this enhancement?