from fastapi import FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware import json app = FastAPI() @app.post("/get_callback") async def get_callback(request: Request): try: json_data = await request.json() challenge = json_data.get("challenge") if challenge is not None: # is a verification request, just return the challenge return {"challenge": challenge} else: # is a callback request, do your own logic here # { # "task_id": "115334141465231360", # "status": "Success", # "file_id": "205258526306433", # "base_resp": { # "status_code": 0, # "status_msg": "success" # } # } return {"status": "success"} except Exception as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": import uvicorn uvicorn.run( app, # required host="0.0.0.0", # Required port=8000, # Required, the port can be configured. # ssl_keyfile='yourname.yourDomainName.com.key', # Optional, check whether SSL is enabled. # ssl_certfile='yourname.yourDomainName.com.key', # Optional, check whether SSL is enabled. )