小编Haj*_*zip的帖子

`pd.read_sql(sql, engine)` 引发 NotImplementedError:此方法未针对 SQLAlchemy 2.0 实现

我尝试使用 sqlalchemy 引擎直接从 sqlserver 数据库创建 pandas DataFrame:

engine = create_engine(URL_string, echo=False, future=True)
query_string = "..."
dt = pd.read_sql(query_string, engine)
Run Code Online (Sandbox Code Playgroud)

但这会引发此错误:

File <redacted>/venv/lib/python3.8/site-packages/sqlalchemy/future/engine.py:320, in Engine._not_implemented(self, *arg, **kw)
    319 def _not_implemented(self, *arg, **kw):
--> 320     raise NotImplementedError(
    321         "This method is not implemented for SQLAlchemy 2.0."
    322     )

NotImplementedError: This method is not implemented for SQLAlchemy 2.0.
Run Code Online (Sandbox Code Playgroud)

我这样做是因为单独使用 pyodbc 的连接会发出警告:

UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy pandas read-sql

7
推荐指数
1
解决办法
8733
查看次数

如何配置 traefik 来处理 CORS 预检请求?

我有一个非常简单的 FastAPI-Traefik-Docker 设置,您可以在这里找到: https: //github.com/mshajarrazip/fastapi-traefik-docker-cors

\n

只需docker-compose up -d运行 FastAPI 和 traefik 服务即可。

\n

此设置中未配置 TLS/SSL。

\n

该应用程序有两个端点 GET“/hello”和 POST“/add”,它们除了返回 json 响应之外什么也不做:

\n

app/main.py

\n
import logging\n\nfrom app import routes\nfrom fastapi import FastAPI\nfrom fastapi.middleware.cors import CORSMiddleware\n\ndef create_application() -> FastAPI:\n    app = FastAPI(title="\xe2\x9c\xa8 ML API \xe2\x9c\xa8")\n\n    app.include_router(routes.hello.router)\n\n    # add CORS\n    # origins = ["*"]\n    app.add_middleware(\n        CORSMiddleware,\n        allow_origins=["*"], # Allows all origins\n        allow_credentials=True,\n        allow_methods=["*"], # Allows all methods\n        allow_headers=["*"], # Allows all headers\n        )\n\n    return app\n\n\napp = create_application()\n
Run Code Online (Sandbox Code Playgroud)\n …

cors preflight docker traefik fastapi

1
推荐指数
1
解决办法
7103
查看次数

标签 统计

cors ×1

docker ×1

fastapi ×1

pandas ×1

preflight ×1

python ×1

read-sql ×1

sqlalchemy ×1

traefik ×1