hey, gays!
I wrote a URL, but the URL could not be found.The service managed by systemctl.
here is code:
# url
service.api_bp.add_route(service.Scripts.as_view(), "/scripts")
# this url can't found.
service.api_bp.add_route(service.RunScripts.as_view(), "/scripts/<filename:str>")
# class view
class RunScripts(HTTPMethodView):
"""
run python script.
"""
async def get(self, request: Request, filename: str) -> HTTPResponse:
"""
run python script.
:param request: Request
:param filename: str, python scripts name. em alice.py
:return:HTTPResponse
"""
file = parse.unquote(filename)
name = file.split(".")[0]
msg = ""
try:
file = __import__(name)
assert hasattr(file, "main"), "The scripts no main function"
msg = file.main()
except Exception as e:
msg = e
finally:
sys.modules.pop(name)
del file
return json(msg)
result
[root@localhost azkaban]# curl http://127.0.0.1:8000/api/scripts/IsAlivedEq1ContentEqNone.py
<!DOCTYPE html><html lang=en><meta charset=UTF-8><title>⚠️ 404 — Not Found</title>
<style>
html { font-family: sans-serif }
h2 { color: #888; }
.tb-wrapper p { margin: 0 }
.frame-border { margin: 1rem }
.frame-line > * { padding: 0.3rem 0.6rem }
.frame-line { margin-bottom: 0.3rem }
.frame-code { font-size: 16px; padding-left: 4ch }
.tb-wrapper { border: 1px solid #eee }
.tb-header { background: #eee; padding: 0.3rem; font-weight: bold }
.frame-descriptor { background: #e2eafb; font-size: 14px }
</style>
<h1>⚠️ 404 — Not Found</h1><p>Requested URL /api/scripts/IsAlivedEq1ContentEqNone.py not found