"ValueError: 'not' is not a valid parameter name" on python 3.11
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
import fastapi
app = fastapi.FastAPI()
@app.get("/")
def index():
return {"message": "Hello World"}
Description
In Python 3.11 (Python 3.11.0b3 (main, Jun 1 2022, 13:29:14) [MSC v.1932 64 bit (AMD64)]), importing fastapi raises an exception: ValueError: 'not' is not a valid parameter name. (Running the file in Python 3.10, 3.9, and 3.8 works as expected)
Traceback
Running the file
Traceback (most recent call last):
File "C:\Users\Tibi\Documents\example.py", line 1, in <module>
import fastapi
^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\applications.py", line 15, in <module>
from fastapi import routing
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 23, in <module>
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 <module>
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 <module>
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 <module>
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 <module>
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 uvicorn
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\__main__.py", line 4, in <module>
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 "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 939, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\Tibi\Documents\.\example.py", line 1, in <module>
import fastapi
^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\applications.py", line 15, in <module>
from fastapi import routing
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Tibi\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 23, in <module>
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 <module>
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 <module>
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 <module>
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 <module>
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 not_: Optional["Schema"] = None, there’s another similar exception: ValueError: 'in' is not a valid parameter name, which is because of this:
# 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 in_: ParameterInType, there’s another similar exception: ValueError: 'in' is not a valid parameter name, which is because of this:
# 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 in_: APIKeyIn, the code works as expected.
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.78.0
Python Version
Python 3.11.0b3
Additional Context
If you would like to, I could make a PR that removes these aliases.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:7

Top Related StackOverflow Question
This issue has been resolved in v1.10.0a1 of Pydantic.
Having the same issue on ARM-64 MacOS with Python 3.11.0b3