-
First Check
Commit to Help
Example Codeimport fastapi
app = fastapi.FastAPI()
@app.get("/")
def index():
return {"message": "Hello World"} DescriptionIn Python 3.11 ( TracebackRunning the fileTraceback (most recent call last): File "C:\Users\Tibi\Documents\example.py", line 1, in import fastapi ^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\__init__.py", line 7, in from .applications import FastAPI as FastAPI ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\applications.py", line 15, in from fastapi import routing ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 23, in from fastapi.dependencies.models import Dependant ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\dependencies\models.py", line 3, in from fastapi.security.base import SecurityBase ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\__init__.py", line 1, in from .api_key import APIKeyCookie as APIKeyCookie ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\api_key.py", line 3, in from fastapi.openapi.models import APIKey, APIKeyIn ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py", line 103, in class Schema(BaseModel): ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 292, in __new__ cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\utils.py", line 258, in generate_model_signature merged_params[param_name] = Parameter( ^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\inspect.py", line 2715, in __init__ raise ValueError('{!r} is not a valid parameter name'.format(name)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: 'not' is not a valid parameter name Using uvicornTraceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\__main__.py", line 4, in uvicorn.main() ^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1128, in __call__ return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1053, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 754, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\main.py", line 437, in main run(app, **kwargs) ^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\main.py", line 463, in run server.run() ^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 60, in run return asyncio.run(self.serve(sockets=sockets)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 181, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 115, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 67, in serve config.load() ^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\config.py", line 458, in load self.loaded_app = import_from_string(self.app) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\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\Tibi\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 939, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\Tibi\Documents\.\example.py", line 1, in import fastapi ^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\__init__.py", line 7, in from .applications import FastAPI as FastAPI ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\applications.py", line 15, in from fastapi import routing ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 23, in from fastapi.dependencies.models import Dependant ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\dependencies\models.py", line 3, in from fastapi.security.base import SecurityBase ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\__init__.py", line 1, in from .api_key import APIKeyCookie as APIKeyCookie ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\security\api_key.py", line 3, in from fastapi.openapi.models import APIKey, APIKeyIn ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py", line 103, in class Schema(BaseModel): ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\main.py", line 292, in __new__ cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\pydantic\utils.py", line 258, in generate_model_signature merged_params[param_name] = Parameter( ^^^^^^^^^^ File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\inspect.py", line 2715, in __init__ raise ValueError('{!r} is not a valid parameter name'.format(name)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: 'not' is not a valid parameter name The problem seems to be this line: # File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py"
class Schema(BaseModel):
# ...
# ~~~~~~~~~~~
not_: Optional["Schema"] = Field(default=None, alias="not")
# ... After changing that line to # File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py"
class Parameter(ParameterBase):
name: str
# ~~~~~~~~~~
in_: ParameterInType = Field(..., alias="in") After changing that line to # File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\openapi\models.py"
class APIKey(SecurityBase):
type_ = Field(SecuritySchemeType.apiKey, alias="type")
# ~~~~~~~~~~
in_: APIKeyIn = Field(..., alias="in")
name: str After changing that line to Operating SystemWindows Operating System DetailsNo response FastAPI Version0.78.0 Python VersionPython 3.11.0b3 Additional ContextIf you would like to, I could make a PR that removes these aliases. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 2 replies
-
Having the same issue on ARM-64 MacOS with Python 3.11.0b3
|
Beta Was this translation helpful? Give feedback.
-
This seems to be related to the following issue in CPython: python/cpython#92062 |
Beta Was this translation helpful? Give feedback.
-
The issue is still present in FastAPI 0.79.0 and Python 3.11.0b4. |
Beta Was this translation helpful? Give feedback.
-
Any thoughts on whether or not simply removing the aliases as described in the original report is an appropriate fix? |
Beta Was this translation helpful? Give feedback.
-
I found that removing the aliases as suggested leads to errors even collecting the test suite, let alone running the tests, since these aliases are used quite heavily. |
Beta Was this translation helpful? Give feedback.
-
The python-fastapi package will be retired from Fedora Linux beginning with Fedora 37 due to this issue. |
Beta Was this translation helpful? Give feedback.
-
This issue has been resolved in v1.10.0a1 of Pydantic. |
Beta Was this translation helpful? Give feedback.
-
I'm getting this error after generating the ml template using cookiecutter |
Beta Was this translation helpful? Give feedback.
This issue has been resolved in v1.10.0a1 of Pydantic.