Failed to load API definition due to local variable 'status_code' referenced before assignment in openapi/utils.py line 267 #6192
-
First Check
Commit to Help
Example CodeInstruction on how to fix the problem is in additional context but I don't know what is causing it so I cannot create a short program that shows the problem and the code I am working on is proprietary so I cannot post it here.DescriptionBrowse to /docs Operating SystemmacOS Operating System DetailsAlso appear in a linux docker environment FastAPI Version0.76.0 Python Version3.8.13 Additional ContextFrom openapi/utils.py line 261 261 status_code_param = response_signature.parameters.get("status_code") The doc load successully if I added the bold text between line 264-265 The following is the error trace: |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
your response class should have a default status_code. |
Beta Was this translation helpful? Give feedback.
-
|
I added status_code to my response class, it didn't help, still have the error. Here is my response class: |
Beta Was this translation helpful? Give feedback.
-
|
if this is your default response class. you should change your args for init method. if this is your return value in endpoints, it should not have such exception |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help here @ycd ! 👏 🙇 If that solves the original problem, then you can close this issue @karenlaw ✔️ |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
if this is your default response class. you should change your args for init method. if this is your return value in endpoints, it should not have such exception