我正在尝试在 FastAPI 中连接到 mongodb。我反复收到此异常。
文件 - main.py
app = FastAPI(
title=config.PROJECT_NAME, docs_url="/api/docs", openapi_url="/api"
)
@app.get("/api/testing")
async def testit():
user_collection = readernetwork_db.get_collection("user_collection")
all_users = await user_collection.find_one({"email": "sample_email"})
print("all users --- ", all_users)
return all_users
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", reload=True, port=8888)
Run Code Online (Sandbox Code Playgroud)
文件 - session.py
import motor.motor_asyncio
from app.core import config
print("here we go again....")
client = motor.motor_asyncio.AsyncIOMotorClient(
config.MONGOATLAS_DATABASE_URI)
readernetwork_db = client.get_database("readernetwork")
Run Code Online (Sandbox Code Playgroud)
例外 -:
all_users = await user_collection.find_one({"email": "sample_email"})
RuntimeError: Task <Task pending name='Task-4' coro=<RequestResponseCycle.run_asgi() running at /usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py:389> cb=[set.discard()]> got Future …Run Code Online (Sandbox Code Playgroud) 之前我使用过 Heroku,设置环境变量非常简单。
heroku config:set my_variable="TEST"
Run Code Online (Sandbox Code Playgroud)
现在,我已经开始使用Digital Ocean,但我不知道如何设置它。我的服务器在Ubuntu上。
例如,对于N = 3. 排列是:
[1,3,2]
[2,3,1]
Run Code Online (Sandbox Code Playgroud)
注意:[1,2,3]并且[3,2,1]在此处无效,因为[1,2,3]增加但不减少,反之亦然[3,2,1].
我在TCS CodeVita 2017中遇到了这个问题,他们甚至没有为此提供社论.