Skip to content

Commit a02bb78

Browse files
author
GillesFischerV
committed
Fix CAMS message error handler - Issue#1799
1 parent 63a2ca4 commit a02bb78

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pvlib/iotools/sodapro.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,14 @@ def get_cams(latitude, longitude, start, end, email, identifier='mcclear',
215215
res = requests.get(base_url + '?DataInputs=' + data_inputs, params=params,
216216
timeout=timeout)
217217

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

0 commit comments

Comments
 (0)