question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"ValueError: 'not' is not a valid parameter name" on python 3.11

See original GitHub issue

First 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:closed
  • Created a year ago
  • Reactions:6
  • Comments:7

github_iconTop GitHub Comments

8reactions
koviubi56commented, Aug 27, 2022

This issue has been resolved in v1.10.0a1 of Pydantic.

3reactions
alexfromapexcommented, Jun 19, 2022

Having the same issue on ARM-64 MacOS with Python 3.11.0b3

Traceback (most recent call last):
  File "/Users/alex/Code/Python/Flashcard/main.py", line 1, in <module>
    from fastapi import FastAPI
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/applications.py", line 15, in <module>
    from fastapi import routing
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/routing.py", line 23, in <module>
    from fastapi.dependencies.models import Dependant
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/dependencies/models.py", line 3, in <module>
    from fastapi.security.base import SecurityBase
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/security/__init__.py", line 1, in <module>
    from .api_key import APIKeyCookie as APIKeyCookie
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/security/api_key.py", line 3, in <module>
    from fastapi.openapi.models import APIKey, APIKeyIn
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/fastapi/openapi/models.py", line 103, in <module>
    class Schema(BaseModel):
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/pydantic/main.py", line 292, in __new__
    cls.__signature__ = ClassAttribute('__signature__', generate_model_signature(cls.__init__, fields, config))
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/envs/notecards/lib/python3.11/site-packages/pydantic/utils.py", line 258, in generate_model_signature
    merged_params[param_name] = Parameter(
                                ^^^^^^^^^^
  File "/Users/alex/.pyenv/versions/3.11-dev/lib/python3.11/inspect.py", line 2715, in __init__
    raise ValueError('{!r} is not a valid parameter name'.format(name))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Read more comments on GitHub >

github_iconTop Results From Across the Web

Built-in Exceptions — Python 3.11.1 documentation
Two exception classes that are not related via subclassing are never ... When set it represent the name of the variable that was...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements;...
Read more >
Issue 19611: inspect.getcallargs doesn't properly interpret set ...
isidentifier(): -> 2400 raise ValueError('{!r} is not a valid parameter name'.format(name)) 2401 ValueError: '.0' is not a valid parameter name ...
Read more >
What's New In Python 3.11 — Python 3.11.1 documentation
When an active exception is re-raised by a raise statement with no parameters, the traceback attached to this exception is now always sys.exc_info()[1].__ ......
Read more >
Exception Handling — Python 3.11.1 documentation
The former corresponds to an exception that is not yet caught (and is therefore ... The format and subsequent parameters help format the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found