等待resp.prepare(request)AttributeError:'NoneType'对象没有属性'prepare'

时间:2018-12-18 12:41:29

标签: python attributeerror aiohttp pytest-aiohttp

async def index(request):
    async with aiohttp.ClientSession() as client:
        data=await(email_verification(client))


        await client.post('http://127.0.0.1:8000/acc/signup',data=data)



async def email_verification(client):
    async with client.get('http://www.mocky.io/v2/5c18dfb62f00005b00af1241') as resp:

        return await(resp.json())

但是每当我尝试访问URL时,我都会收到此错误

   await resp.prepare(request)
AttributeError: 'NoneType' object has no attribute 'prepare'

我什至不知道问题出在哪里,以及这个准备从何而来

1 个答案:

答案 0 :(得分:1)

Web处理程序应返回一个响应对象,而不是无。

固定代码为:

async def index(request):
    async with aiohttp.ClientSession() as client:
        data=await(email_verification(client))
        await client.post('http://127.0.0.1:8000/acc/signup',data=data)
    return web.Response(text="OK")

async def email_verification(client):
    async with client.get('http://www.mocky.io/v2/5c18dfb62f00005b00af1241') as resp:
        return await(resp.json())