k
Hi, I'm having some issues with the venv/uvicorn/fastapi backend. Everytime I run the app (
npm run start
) I get this error:
Copy code
backend/venv/lib/python3.11/site-packages/supertokens_python/utils.py:197: RuntimeWarning: Inconsistent mode detected, check if you are using the right asgi / wsgi mode
  warnings.warn(
INFO:     Started server process [57048]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3001 (Press CTRL+C to quit)
The app runs fine, but now I'm wanting to do some more development on the backend, I'm having issues as I can't access Uvicorn. For example, when I try and visit the server at http://0.0.0.0:3001 I get an internal server error and it throws up a load of other errors:
Copy code
INFO:     127.0.0.1:58983 - "GET / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
I've been reading up about the errors and could be to do with me running this on an M1 Mac, so I've tried running Terminal in Rosetta and reinstalling everything, but it's still throwing up these errors. The full list of errors is shown in the screenshot below. Have you got any experience of these errors and what I can do to fix it? Thanks
r
Hey. @KShivendu can help here.
k
> I'm having issues as I can't access Uvicorn Why? Is this not running locally? Can you share your supertokens python setup code? Please also share how are you starting the server.
@Kranos ^
k
Thanks for getting back to me, no I get an internal server error every time I try to access Uvicorn.
I am starting the server using npm run start in the parent folder that has both the frontend and backend folders in it
This then runs the following in the backend folder:
pip install virtualenv && virtualenv venv && chmod +x venv/bin/activate && . venv/bin/activate && pip install -r requirements.txt && python app.py
This then results in the following:
So, Uvicorn does get up and running on
http://0.0.0.0:3001
as expected. However when you try to access it, it will throw an
Internal Server Error
and produce the following in the Terminal:
I haven't changed the supertokens python set up code and have these two files in the backend folder: app.py and config.py
app.py is as follows:
Copy code
@app.get("/sessioninfo")    
async def secure_api(s: SessionContainer = Depends(verify_session())):
    return {
        "sessionHandle": s.get_handle(),
        "userId": s.get_user_id(),
        "accessTokenPayload": s.get_access_token_payload(),
    }


app = CORSMiddleware(
    app=app,
    allow_origins=[config.app_info.website_domain],
    allow_credentials=True,
    allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
    allow_headers=["Content-Type"] + get_all_cors_headers(),
)

if __name__  == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=3001)
config.py as follows:
Copy code
from supertokens_python.recipe import session, thirdpartyemailpassword, dashboard, emailverification, usermetadata
from supertokens_python.recipe.thirdpartyemailpassword import (
    Apple,
    Github,
    Google,
)
from supertokens_python import (
    InputAppInfo,
    SupertokensConfig,
)

# this is the location of the SuperTokens core.
supertokens_config = SupertokensConfig(
    # https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
    connection_uri="https://dev-32918f51bebd11eda5a2f94364e3b284-eu-west-1.aws.supertokens.io:3569",
    api_key="MY_API_KEY_HERE"
)

app_info = InputAppInfo(
    app_name="panda.ai",
    api_domain="http://localhost:3001",
    website_domain="http://localhost:3000",
)

framework = "fastapi"

# recipeList contains all the modules that you want to
# use from SuperTokens. See the full list here: https://supertokens.com/docs/guides
recipe_list = [
    session.init(), # initializes session features
    thirdpartyemailpassword.init(
        providers=[
            # We have provided you with development keys which you can use for testing.
            # IMPORTANT: Please replace them with your own OAuth keys for production use.
            Google(
                is_default=True,
                client_id="1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
                client_secret="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"
            ),
            # Facebook(
            #     client_id='FACEBOOK_CLIENT_ID',
            #     client_secret='FACEBOOK_CLIENT_SECRET'
            # ),
            Github(
                is_default=True,
                client_id="467101b197249757c71f",
                client_secret="e97051221f4b6426e8fe8d51486396703012f5bd",
            ),
            Apple(
                is_default=True,
                client_id="4398792-io.supertokens.example.service",
                client_key_id="7M48Y4RYDL",
                client_team_id="YWQCXGJRJL",
                client_private_key="-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
            ),
        ]
    ),
    usermetadata.init(),
    emailverification.init(mode='REQUIRED'),
    dashboard.init(api_key="MY_API_KEY_HERE")
]
Hi @KShivendu - did you get a chance to look at this at all? I've done some more testing and I can't work out how my app is even working with this error - I can't even ping
http://localhost:3001
without creating an
Internal Server Error
so I'm not sure how my app is calling
/sessioninfo
correctly and not crashing
r
hey @Kranos - @KShivendu will reply as soon as he is available
k
Thank you!
k
Hey @Kranos, I was able to replicate the issue on my machine. So basically it's happening because of (breaking) changes in
asyncio
of python3.11. I noticed that some other OSS projects have also reported this issue https://github.com/home-assistant/core/issues/88990 The simplest solution is to simply downgrade to python 3.10 which is more stable. If you're using Debian based os, you can do:
Copy code
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
I hope it helps. Let me know if you need help with anything else πŸ˜„
k
Amazing, thank you - will give it a try!
Hi, I managed to downgrade to 3.10.10 but now when I run the app, it crashes out with the following: I think this is because I'm running an M1 mac?
Copy code
Traceback (most recent call last):
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/app.py", line 8, in <module>
    from supertokens_python.recipe.session import SessionContainer
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/__init__.py", line 27, in <module>
    from .recipe import SessionRecipe
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/recipe.py", line 58, in <module>
    from .recipe_implementation import (
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/recipe_implementation.py", line 32, in <module>
    from . import session_functions
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/session_functions.py", line 21, in <module>
    from .access_token import get_info_from_access_token
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/access_token.py", line 22, in <module>
    from .jwt import ParsedJWTInfo, verify_jwt
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/supertokens_python/recipe/session/jwt.py", line 20, in <module>
    from Crypto.Hash import SHA256
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/SHA256.py", line 29, in <module>
    _raw_sha256_lib = load_pycryptodome_raw_lib("Crypto.Hash._SHA256",
  File "/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/_raw_api.py", line 309, in load_pycryptodome_raw_lib
    raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))
OSError: Cannot load native module 'Crypto.Hash._SHA256': Not found '_SHA256.cpython-310-darwin.so', Cannot load '_SHA256.abi3.so': cannot load library '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so': dlopen(/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so, 0x0002): tried: '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (no such file), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (no such file), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')).  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so', Not found '_SHA256.so'
ERROR: "start:backend" exited with 1.
k
Indeed this is happening because of M1. Many other OSS projects have reported this issue with
cryptography
and
pycryptodome
library. You can look into them to find what exactly works for you.
pip install cryptography pycryptodome --no-cache-dir --verbose --force-reinstall
seems to have worked for many people.
@Kranos ^
Unfortunately, I don't have M1 so I cannot replicate it. Let me know if it's still hard to fix this one or if you face some other issue πŸ˜„
k
Thank you! Will git it a go again
Ah, more details here from running that:
I need to downgrade a few things
Argh.... still can't get it working I've downgraded to the following:
cryptography==36.0.2
pycryptodome==3.10.4
And I'm still getting a crash and the same errors:
Copy code
OSError: Cannot load native module 'Crypto.Hash._SHA256': Not found '_SHA256.cpython-310-darwin.so', Cannot load '_SHA256.abi3.so': cannot load library '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so': dlopen(/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so, 0x0002): tried: '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')),

'/System/Volumes/Preboot/Cryptexes/OS/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (no such file), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')),

 '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (no such file), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Hash/_SHA256.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')).

  Additionally, ctypes.util.find_library() did not manage to locate a library called '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.10/site-packages/Crypto/Util/../Hash/_SHA256.abi3.so', Not found '_SHA256.so'

ERROR: "start:backend" exited with 1.
r
yeaa.. this is not even from our sdk anymore - it's from openAI's SDKs
k
I don't think it is, I've just got my project saved in a folder I've called OpenAI...
The issues seem to be in the venv module of Python
And is still the Crypto stuff
r
Ah right ok
Yea I had faced this issue too when moving to m1 Mac.
I had to update my python to the latest one and run a bunch of commands for it to work. Stack over flow helped mostly
I don’t recall what it was. But it was reallly annoying
k
Yeah, going through the same thing! Been on Stackoverflow, GitHub etc looking for solutions and still haven't found the right one yet. Been a couple of days now, hopefully I'll get there!
r
Good luck πŸ™‚
k
Think I'm getting closer now... I'm back on Python 3.11.2 and am just getting two errors relating to Pydantic now:
Copy code
ImportError: dlopen(/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.11/site-packages/pydantic/__init__.cpython-311-darwin.so, 0x0002): tried: '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.11/site-packages/pydantic/__init__.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), 

'/System/Volumes/Preboot/Cryptexes/OS/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.11/site-packages/pydantic/__init__.cpython-311-darwin.so' (no such file), '/Users/sean/Documents/Archive/Coding/OpenAI/panda.ai/backend/venv/lib/python3.11/site-packages/pydantic/__init__.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
I haven't been able to resolve these errors so have decided to run the backend as a Docker container, which seems to be working now and probably a better way to set up in the long run anyway. Thanks for your help though!
k
Cool. You can setup VS code dev containers as well.
25 Views