Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CAMS message error handler #1905

Merged
merged 14 commits into from
Dec 12, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pvlib/iotools/sodapro.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,15 @@ def get_cams(latitude, longitude, start, end, email, identifier='mcclear',
res = requests.get(base_url + '?DataInputs=' + data_inputs, params=params,
timeout=timeout)

# Invalid requests returns an XML error message and the HTTP staus code 200
# as if the request was successful. Therefore, errors cannot be handled
# automatic (e.g. res.raise_for_status()) and errors are handled manually
if res.headers['Content-Type'] == 'application/xml':
# Response from CAMS follows the status and reason format of PyWPS4
# If an error occurs on our side, we will return error 400 - bad request
# Additional information is available in the response text so
# we add it here
# to the error displayed to facilitate users effort to fix their request
AdamRJensen marked this conversation as resolved.
Show resolved Hide resolved
if not res.ok:
errors = res.text.split('ows:ExceptionText')[1][1:-2]
raise requests.HTTPError(errors, response=res)
res.reason = "%s: <%s>" % (res.reason, errors)
res.raise_for_status()
# Successful requests returns a csv data file
elif res.headers['Content-Type'] == 'application/csv':
AdamRJensen marked this conversation as resolved.
Show resolved Hide resolved
fbuf = io.StringIO(res.content.decode('utf-8'))
Expand Down
Loading