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

Closed
kytta opened this issue May 5, 2024 · 11 comments · May be fixed by #11664
Closed

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

kytta opened this issue May 5, 2024 · 11 comments · May be fixed by #11664

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

@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.

@kneelesh48
Copy link

kneelesh48 commented May 24, 2024

Also need to set node version to 18.x in package.json using the code below

{
    "engines": {
        "node": "18.x"
    }
}

@sunnad99
Copy link

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?

I would say, switch to flask. Sanic won't work either since its an async framework like FastAPI.

If you can't change the code, I suggest using render.com then because clearly Vercel don't have time for the python community.

Also need to set node version to 18.x in package.json using the code below

{
    "engines": {
        "node": "18.x"
    }
}

I actually didn't have to do this, it worked just from changing the setting from the vercel dashboard in the project settings.

@kytta
Copy link
Author

kytta commented May 30, 2024

Closed via #11675

@kytta kytta closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants