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

Python runtime does not work on Python 3.12 with ASGI #11545

Open
kytta opened this issue May 5, 2024 · 8 comments · May be fixed by #11541
Open

Python runtime does not work on Python 3.12 with ASGI #11545

kytta opened this issue May 5, 2024 · 8 comments · May be fixed by #11541

Comments

@kytta
Copy link

kytta commented May 5, 2024

Although Python 3.12 is listed as supported by Vercel, it does not work properly with asynchronous functions.

I am trying to deploy a Starlette app (which is ASGI). Just listing Starlette as dependency did not work, as Vercel complained that it's missing aiohttp:

LAMBDA_WARNING: Unhandled exception. [...]
[ERROR] Runtime.ImportModuleError: Unable to import module 'vc__handler__python': No module named 'aiohttp'
Traceback (most recent call last):

So, I've added it to the dependencies (although I don't see the point in it). Nevertheless, it now fails with a different error:

LAMBDA_WARNING: Unhandled exception. [...]
[ERROR] TypeError: Queue.__init__() got an unexpected keyword argument 'loop'
Traceback (most recent call last):
  File "/var/task/vc__handler__python.py", line 305, in vc_handler
    response = asgi_cycle(__vc_module.app, body)
  File "/var/task/vc__handler__python.py", line 202, in __call__
    self.app_queue = asyncio.Queue(loop=loop)

I could trace back to this line of vc_init:

self.app_queue = asyncio.Queue(loop=loop)

According to the Python docs, the loop argument to the Queue was removed in Python 3.10

@sunnad99
Copy link

sunnad99 commented May 6, 2024

I encountered the same issue @kytta

I, temporarily, solved my issue by downgrading to python 3.9.

https://github.com/orgs/vercel/discussions/6729

@PaParaZz1
Copy link

I encountered the same issue @kytta

I, temporarily, solved my issue by downgrading to python 3.9.

https://github.com/orgs/vercel/discussions/6729

Could you please provide an example of vercel.json? I have changed my settings to py3.9 but it doesn't work (still py3.12).

{
  "builds": [
    {
      "src": "main.py",
      "use": "@vercel/python",
      "config": {
        "legacy": true
      }
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "main.py"
    }
  ]
}

@kytta kytta changed the title Python runtime does not work on Python 3.12 with async functions Python runtime does not work on Python 3.12 with ASGI May 6, 2024
@sunnad99
Copy link

sunnad99 commented May 6, 2024

I encountered the same issue @kytta
I, temporarily, solved my issue by downgrading to python 3.9.
https://github.com/orgs/vercel/discussions/6729

Could you please provide an example of vercel.json? I have changed my settings to py3.9 but it doesn't work (still py3.12).

{
  "builds": [
    {
      "src": "main.py",
      "use": "@vercel/python",
      "config": {
        "legacy": true
      }
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "main.py"
    }
  ]
}

There is nothing wrong with your config. Also, the config field in the builds object is unnecessary. To tell vercel to pick up the correct version of python, you need to add the "Pipfile" and "Pipfile.lock"

My vercel.json config file looks like:

{
  "builds": [
    {
      "src": "app.py",
      "use": "@vercel/python"
    }
  ],
  "routes": [
    {
      "src": "(.*)",
      "dest": "app.py"
    }
  ]
}

My pipfile looks like:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
fastapi = "==0.111.0"
requests = "==2.31.0"
beautifulsoup4 = "==4.12.3"
html2text = "==2024.2.26"
validators = "==0.28.1"

[dev-packages]

[requires]
python_version = "3.9"
python_full_version = "3.9.13"

Check the following links out for more info:
https://vercel.com/docs/functions/runtimes/python#python-version
https://vercel.com/docs/deployments/build-image/build-image-legacy
https://vercel.com/docs/functions/runtimes/node-js#setting-the-node.js-version-in-project-settings

@ernests
Copy link

ernests commented May 6, 2024

There is a pull request which solves the problem - #11541

@sunnad99
Copy link

sunnad99 commented May 6, 2024

There is a pull request which solves the problem - #11541

yes, but while its not live, the solution should be made clear to the users

@kytta kytta linked a pull request May 6, 2024 that will close this issue
@jeremyk
Copy link

jeremyk commented May 10, 2024

I also hit this issue - would really like to avoid downgrading both node and python - any idea when the associated PR will be merged and released?

@Zapzatron
Copy link

Same problem, waiting for the PR to be accepted

@adamstoffel
Copy link

+1 FastAPI does not work until this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants