-
Notifications
You must be signed in to change notification settings - Fork 10
Description
This is not an issue, but a change request.
Currently, when requests return a non-200 error, the ONC package returns an HTTPError.
For scripts that download large amounts of data, this may end up blocking subsequent requests if an error is raised and a user is not aware of all possibilities.
The following snippet...
params = {'locationCode': 'BACVP',
'deviceCategoryCode': 'CTD',
'dateFrom':'2025-01-01T00:00:00.000Z',
'dateTo':'2025-01-01T23:59:59.999Z'}
data = onc.getScalardata(filters = params, allPages=True)
returns this error...
HTTPError:
Status 400 - Bad Request: https://data.oceannetworks.ca/api/scalardata?locationCode=BACVP&deviceCategoryCode=CTD&dateFrom=2025-01-01T00%3A00%3A00.000Z&dateTo=2025-01-01T23%3A59%3A59.999Z&method=getByLocation&token=<>
API Error 127: A device with category CTD was deployed at location BACVP but not during the provided time range (20250101T000000.000Z to 20250101T235959.999Z). The deployment service can be used to determine a valid time range: https://data.oceannetworks.ca/api/deployments?locationCode=BACVP&deviceCategoryCode=CTD&token=<> (parameter: locationCode, deviceCategoryCode, dateFrom, dateTo)
The courteous thing to do would be to follow the recommendation of hitting the deployments endpoint, but like myself, users may just find it easier to force subsequent requests for data until data is returned. If not in a try-except statement that then parses the returned error, a script may stop.
Would it be possible to add a boolean keyword argument to the ONC class that instead offers the option of returning the full output from the request response, rather than raising an HTTPError? This would allow users to use the full functionality of the requests package and allow them to better tune download scripts for bad data requests or system downtimes.
For example...
import requests
onc = ONC(token = token, full_response_on_error = True)
response = onc.getScalardata(filters = params, allPages=True)
if response.status_code == requests.codes.ok:
# Do stuff with the data.
elif response.status_code == requests.codes.bad:
# Do stuff with the rest of the script.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status