python-3.x - 如何在 Sanic 中使用依赖注入实现 CORS
问题描述
我正在使用依赖注入库在 Sanic 中构建 API,并且正在尝试实现 CORS。
我试图将 Sanic 类分配给一个变量并将其CORS()
传递__name__
给providers.Factory
.
下面的评论显示了我尝试实现 CORS 的确切行:
from sanic_cors import CORS, cross_origin # imported the Sanic_cors here
class Application(containers.DeclarativeContainer):
"""
Application components container
"""
# declared the app variable here and passed the Sanic class
app = Sanic()
# passed the variable in to CORS()
CORS(app)
webapi = providers.Factory(app, __name__)
我预计运行 API 不会出错,但我在下面收到此错误:
Traceback (most recent call last):
File "api.py", line 7, in <module>
run_api(APP)
File "/Users/Kassim/Documents/Projects/pythonProjects/my-app-engine/app/api_runner.py", line 8, in run_api
web_api = application.webapi()
File "src/dependency_injector/providers.pyx", line 100, in dependency_injector.providers.Provider.__call__
File "src/dependency_injector/providers.pyx", line 1247, in dependency_injector.providers.Factory._provide
File "src/dependency_injector/providers.pxd", line 278, in dependency_injector.providers.__factory_call
File "src/dependency_injector/providers.pxd", line 272, in dependency_injector.providers.__callable_call
TypeError: __call__() takes 1 positional argument but 2 were given
解决方案
推荐阅读
- typescript - 如何允许作为类键的字符串
- wso2 - wso2 问题在 magento2 api 上使用呼叫调解器
- node.js - 如何在 Jest/NestJS 中模拟第三方模块?
- javascript - 在 Cypress.io 中,如何勾选包含同名元素但我只想勾选其中一个项目的跨度中的项目
- dc.leaflet.js - 未捕获的类型错误:无法分配给“sme_site”上的属性“_leaflet_id”:不是对象
- javascript - JavaScript 播放和托管音频的下载链接
- python - sns.despine 限制 x 和 y 轴
- java - MapStruct 无法从对象中提取枚举值
- ios - 根据用户操作在表格单元格视图中排列多个 UIView 向左或向右移动(使用 Xamarin IOS 和 XIB)
- angular - Angular:从组件中的指令调用方法