async-await - AIOHTTP:TypeError: index() 接受 0 个位置参数,但给出了 1 个
问题描述
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)
主文件
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
但是 ti 可以在终端中打印 json 但无法在浏览器中触发与 Web 响应相同的响应我不知道在这种情况下出了什么问题
解决方案
推荐阅读
- javascript - 如何从 javascript 运行 pyton 代码?我想在上传前处理文件
- spring - 为什么 Spring 测试不与 Embedded Mongo 重用相同的 Context
- python - 在 python 中处理海龟图形并调用导入的函数
- git - 不能锁定只读的neatbeans
- typescript - 带有 postgres 的 typeorm:没有找到 [] 的存储库。看起来这个实体没有在当前的“默认”连接中注册?
- r - 在ggplot中移动并左对齐y轴标签
- javascript - 网站发出 POST 请求,我怎样才能用 JS 获得该请求的结果?
- ruby-on-rails - 升级引导程序后编译资产时出错
- java - 如何在 Spring Boot 和 Spring Security 中配置单页 Google 和 Azure OAuth2 登录?
- android - 查看 Activity 和底栏的绑定