【发布时间】:2018-12-13 14:51:46
【问题描述】:
from aiohttp import web
import aiohttp
from settings import config
import asyncio
import psycopg2 as p
import json
import aiopg
import aiohttp
import asyncio
async def fetch(client):
async with client.get('https://jsonplaceholder.typicode.com/todos/1') as resp:
assert resp.status == 200
return await resp.json()
async def index():
async with aiohttp.ClientSession() as client:
html = await fetch(client)
return web.Response(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(index())
这是我的观点.py
from aiohttp import web
from routes import setup_routes
from settings import config
app = web.Application()
setup_routes(app)
web.run_app(app,port=9090)
main.py
from views import index
def setup_routes(app):
app.router.add_get('/', index)
这是我的 routes.py
但是当我尝试触发 localhost:9090 的 url 时,我只是得到一个内部服务器 500 错误 说
TypeError: index() takes 0 positional arguments but 1 was given
但我可以在终端中打印 json,但无法在浏览器中触发与 Web 响应相同的响应,我不知道在这种情况下出了什么问题
【问题讨论】:
标签: async-await python-asyncio aiohttp pytest-aiohttp