从aiohttp导入网站 导入json
async def handle(request):
response_obj = { 'status' : 'success' }
return web.Response(text=json.dumps(response_obj))
async def new_user(request):
try:
print("AT Epoint" )
## happy path where name is set
user = request.query['name']
## Process our new user
print("Creating new user with name: " , user)
response_obj = { 'status' : 'success' }
## return a success json response with status code 200 i.e. 'OK'
return web.Response(text=json.dumps(response_obj), status=200)
except Exception as e:
print("AT EXCEPTION" )
## Bad path where name is not set
response_obj = { 'status' : 'failed', 'reason': str(e) }
## return failed with a status code of 500 i.e. 'Server Error'
return web.Response(text=json.dumps(response_obj), status=500)
答案 0 :(得分:0)