flyinactor91 / fastapi-beanie-jwt Goto Github PK
View Code? Open in Web Editor NEWSample FastAPI server with JWT auth and Beanie ODM
License: MIT License
Sample FastAPI server with JWT auth and Beanie ODM
License: MIT License
←[32mINFO←[0m: Uvicorn running on ←[1mhttp://127.0.0.1:8080←[0m (Press CTRL+C to quit) ←[32mINFO←[0m: Started reloader process [←[36m←[1m18512←[0m] using ←[36m←[1mStatReload←[0m Process SpawnProcess-1: Traceback (most recent call last): File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap self.run() File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 108, in run self._target(*self._args, **self._kwargs) File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\_subprocess.py", line 76, in subprocess_started target(sockets=sockets) File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 61, in run return asyncio.run(self.serve(sockets=sockets)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 68, in serve config.load() File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\config.py", line 467, in load self.loaded_app = import_from_string(self.app) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string module = importlib.import_module(module_str) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "D:\utilities\abcd_frontend\stories_backend\myserver\main.py", line 7, in <module> from myserver import jwt File "D:\utilities\abcd_frontend\stories_backend\myserver\jwt.py", line 7, in <module> from fastapi import Request File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\__init__.py", line 7, in <module> from .applications import FastAPI as FastAPI File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\applications.py", line 3, in <module> from fastapi import routing File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 22, in <module> from fastapi.dependencies.models import Dependant File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\dependencies\models.py", line 3, in <module> from fastapi.security.base import SecurityBase File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\__init__.py", line 1, in <module> from .api_key import APIKeyCookie as APIKeyCookie File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\api_key.py", line 3, in <module> from fastapi.openapi.models import APIKey, APIKeyIn File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py", line 8, in <module> import email_validator # type: ignore ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\email_validator\__init__.py", line 6, in <module> import dns.resolver File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\dns\resolver.py", line 30, in <module> import dns._ddr File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\dns\_ddr.py", line 12, in <module> import dns.nameserver File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\dns\nameserver.py", line 5, in <module> import dns.asyncquery File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\dns\asyncquery.py", line 38, in <module> from dns.query import ( File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\dns\query.py", line 67, in <module> _CoreNetworkBackend = httpcore.NetworkBackend ^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'httpcore' has no attribute 'NetworkBackend'
Thanks for the repo, it was very helpful getting asyncio and pytest to work nicely.
Just one thing i discovered, you might need to add
pytest.ini
[pytest]
asyncio_mode=auto
Otherwise tests fail with errors:
pytest
======================================================================== short test summary info =========================================================================
FAILED tests/routes/test_auth.py::test_not_authorized - AttributeError: 'async_generator' object has no attribute 'get'
FAILED tests/routes/test_auth.py::test_refresh - beanie.exceptions.CollectionWasNotInitialized
FAILED tests/routes/test_user.py::test_user_get - beanie.exceptions.CollectionWasNotInitialized
FAILED tests/routes/test_user.py::test_user_update - beanie.exceptions.CollectionWasNotInitialized
FAILED tests/routes/test_user.py::test_user_delete - beanie.exceptions.CollectionWasNotInitialized
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.