Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_external_mei(meiaddr):
r = requests.get(unquote(meiaddr), timeout=15)
# Exeunt stage left if something went wrong.
if r.status_code != requests.codes.ok:
if r.status_code == 404:
msg = "The MEI File could not be found"
raise CannotAccessRemoteMEIException(msg)
else:
msg = "An unknown error ocurred. Status code: {0}".format(
r.status_code)
raise UnknownMEIReadException(msg)
return r.content
def information(meipath):
try:
mei_as_text = get_external_mei(meipath)
except CannotAccessRemoteMEIException as ex:
return {"message": ex.message}, status.HTTP_400_BAD_REQUEST
except UnknownMEIReadException as ex:
return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR
try:
parsed_mei = meiinfo.read_MEI(mei_as_text).getMeiDocument()
except CannotReadMEIException as ex:
# return a 500 server error with the exception message
return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR
# it's possible that this will raise some exceptions too, so break it out.
try:
mus_doc_info = meiinfo.MusDocInfo(parsed_mei).get()
except BadApiRequest as ex:
return {"message": ex.message}, status.HTTP_500_INTERNAL_SERVER_ERROR