cloudflare / python-workers-examples

Apache License 2.0
106 stars 19 forks source link

Cannot run fastapi demo #9

Closed lvelvee closed 1 week ago

lvelvee commented 5 months ago
$ npx wrangler -v

 ⛅️ wrangler 3.60.3
✘ [ERROR] PythonError: Traceback (most recent call last):

    File "/lib/python312.zip/_pyodide/_base.py", line 629, in pyimport_impl
      res = __import__(stem, fromlist=fromlist)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/session/metadata/worker.py", line 1, in <module>
      from fastapi import FastAPI, Request
    File "/session/lib/python3.12/site-packages/fastapi/__init__.py", line 7, in <module>
      from .applications import FastAPI as FastAPI
    File "/session/lib/python3.12/site-packages/fastapi/applications.py", line 16, in <module>
      from fastapi import routing
    File "/session/lib/python3.12/site-packages/fastapi/routing.py", line 22, in <module>
      from fastapi import params
    File "/session/lib/python3.12/site-packages/fastapi/params.py", line 5, in <module>
      from fastapi.openapi.models import Example
    File "/session/lib/python3.12/site-packages/fastapi/openapi/models.py", line 4, in <module>
      from fastapi._compat import (
    File "/session/lib/python3.12/site-packages/fastapi/_compat.py", line 20, in <module>
      from fastapi.exceptions import RequestErrorModel
    File "/session/lib/python3.12/site-packages/fastapi/exceptions.py", line 3, in <module>
      from pydantic import BaseModel, create_model
    File "<frozen importlib._bootstrap>", line 1412, in _handle_fromlist
    File "/session/lib/python3.12/site-packages/pydantic/__init__.py", line 383, in __getattr__
      module = import_module(module_name, package=package)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/lib/python312.zip/importlib/__init__.py", line 90, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/session/lib/python3.12/site-packages/pydantic/main.py", line 12, in <module>
      import pydantic_core
    File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
    File "/lib/python3.12/site-packages/_cloudflare/import_patch_manager.py", line 27, in
  exec_module
      with self.import_context(module):
    File "/lib/python312.zip/contextlib.py", line 144, in __exit__
      next(self.gen)
    File "/lib/python3.12/site-packages/_cloudflare/entropy_import_context.py", line 123, in
  pydantic_core_context
      with allow_bad_entropy_calls(1):
    File "/lib/python312.zip/contextlib.py", line 144, in __exit__
      next(self.gen)
    File "/lib/python3.12/site-packages/_cloudflare/entropy_import_context.py", line 48, in
  allow_bad_entropy_calls
      raise RuntimeError(
  RuntimeError: 1 unexpected leftover getentropy calls

      at new_error (pyodide-internal:generated/pyodide.asm:20:9998)
      at [object Object]x16c818
      at [object Object]x16c972
      at Module._pythonexc2js (pyodide-internal:generated/pyodide.asm:20:607956)
      at Module.callPyObjectKwargs (pyodide-internal:generated/pyodide.asm:20:64098)
      at Module.callPyObject (pyodide-internal:generated/pyodide.asm:20:65055)
      at Function.apply (pyodide-internal:generated/pyodide.asm:20:79132)
      at Object.apply (pyodide-internal:generated/pyodide.asm:20:77371)
      at Object.pyimport (pyodide-internal:generated/pyodide.asm:20:102862)
      at pyimportMainModule (pyodide:python-entrypoint-helper:31:18)
      at null.<anonymous> (pyodide:python-entrypoint-helper:117:11)
      at enterJaegerSpan (pyodide-internal:jaeger:9:12)
      at null.<anonymous> (pyodide:python-entrypoint-helper:116:16)
      at async preparePython (pyodide:python-entrypoint-helper:129:22)
      at null.<anonymous> (async pyodide:python-entrypoint-helper:139:21)
      at async Object.fetch (pyodide:python-entrypoint-helper:137:26)
Yutsuro commented 5 months ago

+1.

Same problem with wrangler v3.61.0.

How can I run this tutorial?

SZRabinowitz commented 5 months ago

Not sure if this is helpful or not but +1

mikenomitch commented 5 months ago

Hey all, we're currently working on this issue, but probably won't have a new version of wrangler out with the fix until next week. Sorry about this :( We are also updating the gaps in automated testing that allowed us to miss this in the first place.

For the time being, if you downgrade to wrangler 3.55.0, you can get FastAPI working. Hopefully this workaround is only needed until next week.

maxtheman commented 4 months ago

Hey @mikenomitch Sorry to bother you — do you know when the release with this fix incorporated will be out? I see that the fix has been merged: https://github.com/cloudflare/workerd/pull/2324 but it hasn't yet been released (wrangler 3.63.2 has the same problem).

I can confirm that FastAPI works on wrangler 3.55.0 as a workaround.

dom96 commented 4 months ago

It seems the release is currently blocked on https://github.com/cloudflare/workers-sdk/issues/6170. So need to wait for that to be fixed and then we should have a release fairly quickly.

maxtheman commented 4 months ago

Ah, thanks @dom96 , I'll watch that.

Niko-La commented 4 months ago

is this fixed now wrangler is now on 3.68.0 ? if so can close this if demo is up. Last I checked the demo didnt work using online dashboard aswell.

kamasylvia commented 3 months ago

Same problem

dom96 commented 1 week ago

This should be working fine with latest wrangler now. Let us know if that's not the case.