Commit b9c0a950 authored by Franziska Koehn's avatar Franziska Koehn
Browse files

exceptions for statuscodes added

parent d10bf7af
......@@ -184,7 +184,6 @@ def retry_qry(fun):
return fun(*args, **kwargs)
except Exception as e:
print(("wrapped", e))
if type(last_exception) is type(e):
raise e
last_exception = e
......@@ -251,12 +250,27 @@ def search_for(host, root_element, constraints, search_fields, user, passw):
tree = create_xml_tree(root_element, constraints, search_fields)
tree.write(tmp, xml_declaration=True)
r =, files={'file': open(, 'rb')}, auth=HTTPBasicAuth(user, passw))
r =, files={'file': open(, 'rb')}, auth=HTTPBasicAuth(user, passw))
except requests.exceptions.InvalidSchema as e:
raise xsa.errors.ServerNotFoundError(e)
except requests.exceptions.InvalidURL as e:
raise xsa.errors.ServerNotFoundError(e)
except requests.RequestException as e:
raise xsa.errors.Error(e)
if r.status_code ==
return JsonTable(json_file)
elif r.status_code ==
raise xsa.errors.UnauthorizedError("HTTP 401: unauthorized")
elif r.status_code ==
raise xsa.errors.Error("HTTP 403: forbidden (check query definition, e.g. roottype)")
elif r.status_code ==
raise xsa.errors.ServerNotFoundError("HTTP 404: not found (check host-address)")
elif r.status_code ==
raise xsa.errors.Error("HTTP 500: Internal Server Error (check query definition, e.g. constraints)")
def create_xml_tree(root_type, query, fields):
import xml.etree.cElementTree as ET
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment