Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'PROVIDE_AUTOMATIC_OPTIONS' (Flask update) #1173

Closed
alvarorgzalonso opened this issue Nov 14, 2024 · 8 comments
Closed

KeyError: 'PROVIDE_AUTOMATIC_OPTIONS' (Flask update) #1173

alvarorgzalonso opened this issue Nov 14, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@alvarorgzalonso
Copy link

Describe the bug
App won't start after default deployment. I ran the deployment from the Azure OpenAI studio:

Image

This lets you create a WebApp and it deploys it with a link back to this repo.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy the application.
  2. Wait for the deployment to complete as indicated in the studio.
  3. Access the deployed App Service.
  4. Connect to the front end.
  5. Encounter the following application error:
    Image
  6. Notice KeyError: 'PROVIDE_AUTOMATIC_OPTIONS' (trying to access missing key from dict).

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Configuration: Please provide the following

  • Azure OpenAI model name and version: gpt-4o 2024-05-13
  • Is chat history enabled? NO
  • Are you using data? If so, what data source? Azure AI Search
  • Verify the startup command and runtime configuration by showing the output of the following az CLI command:
az webapp show --name <app name> --resource-group <resource group name> --query "{startupCommand: siteConfig.appCommandLine, runtime: siteConfig.linuxFxVersion}"

Output:

{
  "runtime": "PYTHON|3.11",
  "startupCommand": "python3 -m gunicorn app:app"
}

Logs

  1. If the application is crashing after deployment, please share the application logs using the following az CLI command:
az webapp log tail --name <app name> --resource-group <resource group name>
2024-11-14T09:17:56.079664765Z    _____
2024-11-14T09:17:56.079697797Z   /  _  \ __________ _________   ____
2024-11-14T09:17:56.079704350Z  /  /_\  \\___   /  |  \_  __ \_/ __ \
2024-11-14T09:17:56.079710060Z /    |    \/    /|  |  /|  | \/\  ___/
2024-11-14T09:17:56.079715300Z \____|__  /_____ \____/ |__|    \___  >
2024-11-14T09:17:56.079720950Z         \/      \/                  \/
2024-11-14T09:17:56.079726401Z A P P   S E R V I C E   O N   L I N U X
2024-11-14T09:17:56.079731771Z
2024-11-14T09:17:56.079736890Z Documentation: http://aka.ms/webapp-linux
2024-11-14T09:17:56.079742000Z Python 3.11.8
2024-11-14T09:17:56.079747590Z Note: Any data outside '/home' is not persisted
2024-11-14T09:18:03.601278888Z Starting OpenBSD Secure Shell server: sshd.
2024-11-14T09:18:03.842016356Z WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
2024-11-14T09:18:03.951547889Z Site's appCommandLine: python3 -m gunicorn app:app
2024-11-14T09:18:03.953459532Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'python3 -m gunicorn app:app'
2024-11-14T09:18:04.810544737Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2024-11-14T09:18:04.812617486Z Build Operation ID: 8f55ad6ea80affdf
2024-11-14T09:18:04.813522496Z Oryx Version: 0.2.20240501.1, Commit: f83f88d3cfb8bb6d3e2765e1dcd218eb0814a095, ReleaseTagName: 20240501.1
2024-11-14T09:18:04.813590012Z Output is compressed. Extracting it...
2024-11-14T09:18:04.818404618Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8dd04876cddf300'...
2024-11-14T09:18:06.699019076Z App path is set to '/tmp/8dd04876cddf300'
2024-11-14T09:18:07.123746780Z Writing output script to '/opt/startup/startup.sh'
2024-11-14T09:18:08.703836260Z Using packages from virtual environment antenv located at /tmp/8dd04876cddf300/antenv.
2024-11-14T09:18:08.703879380Z Updated PYTHONPATH to '/opt/startup/app_logs:/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages'
2024-11-14T09:18:17.261959552Z [2024-11-14 09:18:17 +0000] [73] [INFO] Starting gunicorn 20.1.0
2024-11-14T09:18:17.261994306Z [2024-11-14 09:18:17 +0000] [73] [INFO] Listening at: http://0.0.0.0:8000 (73)
2024-11-14T09:18:17.262002672Z [2024-11-14 09:18:17 +0000] [73] [INFO] Using worker: uvicorn.workers.UvicornWorker
2024-11-14T09:18:17.266937300Z [2024-11-14 09:18:17 +0000] [75] [INFO] Booting worker with pid: 75
2024-11-14T09:18:17.351235941Z [2024-11-14 09:18:17 +0000] [76] [INFO] Booting worker with pid: 76
2024-11-14T09:18:17.394918174Z [2024-11-14 09:18:17 +0000] [77] [INFO] Booting worker with pid: 77
2024-11-14T09:18:17.412121099Z [2024-11-14 09:18:17 +0000] [78] [INFO] Booting worker with pid: 78
2024-11-14T09:18:17.503306224Z [2024-11-14 09:18:17 +0000] [79] [INFO] Booting worker with pid: 79
2024-11-14T09:18:43.599633576Z /tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.
2024-11-14T09:18:43.599905304Z Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
2024-11-14T09:18:43.599917096Z See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
2024-11-14T09:18:43.599924329Z   warnings.warn(
2024-11-14T09:18:43.599930280Z /tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.
2024-11-14T09:18:43.599936743Z Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
2024-11-14T09:18:43.599942623Z See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
2024-11-14T09:18:43.599948565Z   warnings.warn(
2024-11-14T09:18:43.659586120Z /tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.
2024-11-14T09:18:43.659714911Z Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
2024-11-14T09:18:43.659726512Z See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
2024-11-14T09:18:43.659733435Z   warnings.warn(
2024-11-14T09:18:43.680198019Z /tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.
2024-11-14T09:18:43.680315559Z Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
2024-11-14T09:18:43.680323744Z See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
2024-11-14T09:18:43.680330166Z   warnings.warn(
2024-11-14T09:18:43.685571916Z /tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/pydantic/main.py:214: UserWarning: A custom validator is returning a value other than `self`.
2024-11-14T09:18:43.685653559Z Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.
2024-11-14T09:18:43.685662916Z See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.
2024-11-14T09:18:43.685669969Z   warnings.warn(
2024-11-14T09:18:43.916490090Z [2024-11-14 09:18:43 +0000] [77] [ERROR] Exception in worker process
2024-11-14T09:18:43.916534463Z Traceback (most recent call last):
2024-11-14T09:18:43.916546846Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2024-11-14T09:18:43.916553539Z     worker.init_process()
2024-11-14T09:18:43.916560572Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/uvicorn/workers.py", line 66, in init_process
2024-11-14T09:18:43.916578105Z     super(UvicornWorker, self).init_process()
2024-11-14T09:18:43.916584226Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
2024-11-14T09:18:43.916590147Z     self.load_wsgi()
2024-11-14T09:18:43.916595908Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2024-11-14T09:18:43.916602841Z     self.wsgi = self.app.wsgi()
2024-11-14T09:18:43.916608952Z                 ^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916684393Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
2024-11-14T09:18:43.916696065Z     self.callable = self.load()
2024-11-14T09:18:43.916702868Z                     ^^^^^^^^^^^
2024-11-14T09:18:43.916707526Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2024-11-14T09:18:43.916711714Z     return self.load_wsgiapp()
2024-11-14T09:18:43.916715561Z            ^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916719398Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2024-11-14T09:18:43.916723476Z     return util.import_app(self.app_uri)
2024-11-14T09:18:43.916727313Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916731120Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
2024-11-14T09:18:43.916735108Z     mod = importlib.import_module(module)
2024-11-14T09:18:43.916738945Z           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916742792Z   File "/opt/python/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
2024-11-14T09:18:43.916746739Z     return _bootstrap._gcd_import(name[level:], package, level)
2024-11-14T09:18:43.916750617Z            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916754484Z   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
2024-11-14T09:18:43.916758902Z   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
2024-11-14T09:18:43.916763100Z   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
2024-11-14T09:18:43.916767318Z   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
2024-11-14T09:18:43.916771305Z   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
2024-11-14T09:18:43.916776505Z   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2024-11-14T09:18:43.916780593Z   File "/tmp/8dd04876cddf300/app.py", line 885, in <module>
2024-11-14T09:18:43.916784690Z     app = create_app()
2024-11-14T09:18:43.916788548Z           ^^^^^^^^^^^^
2024-11-14T09:18:43.916798957Z   File "/tmp/8dd04876cddf300/app.py", line 45, in create_app
2024-11-14T09:18:43.916802984Z     app = Quart(__name__)
2024-11-14T09:18:43.916806872Z           ^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916810759Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/quart/app.py", line 336, in __init__
2024-11-14T09:18:43.916814757Z     self.add_url_rule(
2024-11-14T09:18:43.916818864Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/flask/sansio/scaffold.py", line 47, in wrapper_func
2024-11-14T09:18:43.916823002Z     return f(self, *args, **kwargs)
2024-11-14T09:18:43.916826859Z            ^^^^^^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916830696Z   File "/tmp/8dd04876cddf300/antenv/lib/python3.11/site-packages/flask/sansio/app.py", line 641, in add_url_rule
2024-11-14T09:18:43.916834724Z     if "OPTIONS" not in methods and self.config["PROVIDE_AUTOMATIC_OPTIONS"]:
2024-11-14T09:18:43.916838771Z                                     ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-11-14T09:18:43.916842709Z KeyError: 'PROVIDE_AUTOMATIC_OPTIONS'

Additional context
Recent Flask update is causing this issue: Related Issue #371 on Quart's GitHub Repository

@alvarorgzalonso alvarorgzalonso added the bug Something isn't working label Nov 14, 2024
@alvarorgzalonso
Copy link
Author

alvarorgzalonso commented Nov 14, 2024

Solved by changing deployment type to manual (not via WEB) and pinning Flask[async]==3.0.3 on requirements.txt

@alexandreweiss
Copy link

Was using it since two weeks in a manual deployment just cloning the repo. Encountered same issue since today. Pinning flask also did it for me.
Thanks for sharing the tip @alvarorgzalonso !! (I'm newbie on python so really helps)

@alvarorgzalonso
Copy link
Author

For me, it's not really solved; the deployment is successful, but when I go to the page, I get this new error:

2024-11-14T12:40:38.7036427Z TypeError: Quart.__call__() missing 1 required positional argument: 'send'
2024-11-14T12:40:38.9551849Z [2024-11-14 12:40:38 +0000] [94] [ERROR] Error handling request /
2024-11-14T12:40:38.9552302Z Traceback (most recent call last):
2024-11-14T12:40:38.9552345Z   File "/tmp/8dd04a8b3abbcdb/antenv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 136, in handle
2024-11-14T12:40:38.9552375Z     self.handle_request(listener, req, client, addr)
2024-11-14T12:40:38.9555131Z 169.254.129.1 - - [14/Nov/2024:12:40:38 +0000] "GET / HTTP/1.1" 500 0 "-" "-"
2024-11-14T12:40:38.9559002Z   File "/tmp/8dd04a8b3abbcdb/antenv/lib/python3.11/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
2024-11-14T12:40:38.9559087Z     respiter = self.wsgi(environ, resp.start_response)
2024-11-14T12:40:38.9559116Z                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I can imagine it's because of a library version mismatch. Is this happening to you, @alexandreweiss?

@alexandreweiss
Copy link

So, I took Python code and ran it into an AWS EC2 instance to demonstrate some capabilities of our networking product (Aviatrix)
So my EC2 is talking to OpenAI via a private endpoint using the API Key and it works well.
What is you current setup ? Would that 500 you get from the Open AI ? You should have complete response trace.

@alvarorgzalonso
Copy link
Author

@alexandreweiss thank you for your response. The second issue was due to my incorrect configuration of the WebApp variables.

Musa-Anwaar added a commit to Musa-Anwaar/sample-app-aoai-chatGPT that referenced this issue Nov 14, 2024
@jasredyy5
Copy link

Thank you. We had the same issue today and it is fixed by pinning Flask[async]==3.0.3 on requirements.txt.

@wheatsnackbread
Copy link

Confirmed this fix works.

@bronyrafon
Copy link

Confirm this fix works 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants