更新 huaweitest.py
parent
57f7f9252f
commit
fb3d7190b7
|
|
@ -5,12 +5,24 @@ app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root(request: Request):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /")
|
||||||
return "welcome to fastAPI!"
|
return "welcome to fastAPI!"
|
||||||
|
|
||||||
|
|
||||||
@app.get("/script/getscriparam")
|
@app.get("/script/getscriparam")
|
||||||
async def getscriparam():
|
async def getscriparam(request: Request):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /")
|
||||||
data = {
|
data = {
|
||||||
"interaction": {
|
"interaction": {
|
||||||
"from": 20,
|
"from": 20,
|
||||||
|
|
@ -46,7 +58,7 @@ async def do_success(request: Request):
|
||||||
client_host = request.client.host
|
client_host = request.client.host
|
||||||
|
|
||||||
# 打印上报成功的时间和IP地址
|
# 打印上报成功的时间和IP地址
|
||||||
print(f"上报成功时间: {current_time}, IP地址: {client_host}")
|
print(f"请求IP地址: {client_host},上报成功时间: {current_time}")
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
return {
|
return {
|
||||||
|
|
@ -57,12 +69,13 @@ async def do_success(request: Request):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/script/failed")
|
@app.get("/script/failed")
|
||||||
async def do_failed(reason: str = None, errortype: str = None):
|
async def do_failed(request: Request, reason: str = None, errortype: str = None):
|
||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
# 格式化时间为 年-月-日 时:分:秒 的格式
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /script/failed")
|
||||||
# 假设这里记录失败原因到日志或数据库
|
# 假设这里记录失败原因到日志或数据库
|
||||||
print(f"上报失败,Time: {formatted_now}, 失败原因: {reason},失败类型: {errortype}.") # 实际应用中应使用更专业的日志记录方式
|
print(f"上报失败,Time: {formatted_now}, 失败原因: {reason},失败类型: {errortype}.") # 实际应用中应使用更专业的日志记录方式
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue