amagic5502
08/28/2023, 7:48 AM/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/context.py:2695: RuntimeWarning: coroutine 'Supertokens.middleware' was never awaited
_instance = loading._instance_processor(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
ERROR:APP_NAME:Exception on /case/ [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 176, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1482, in full_dispatch_request
rv = self.preprocess_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1974, in preprocess_request
rv = self.ensure_sync(before_func)()
File "/usr/local/lib/python3.9/site-packages/supertokens_python/framework/flask/flask_middleware.py", line 54, in _
result: Union[BaseResponse, None] = sync(st.middleware(request_, response_))
File "/usr/local/lib/python3.9/site-packages/supertokens_python/async_to_sync_wrapper.py", line 33, in sync
return loop.run_until_complete(co)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 623, in run_until_complete
self._check_running()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 583, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
rp_st
08/28/2023, 7:49 AMamagic5502
08/28/2023, 7:50 AMrp_st
08/28/2023, 7:51 AMamagic5502
08/28/2023, 7:52 AMfrom supertokens_python.framework.flask import Middleware
Middleware(app)
rp_st
08/28/2023, 7:54 AMrp_st
08/28/2023, 7:55 AMamagic5502
08/28/2023, 7:57 AMrp_st
08/28/2023, 7:57 AMrp_st
08/28/2023, 7:57 AMrp_st
08/28/2023, 7:57 AMamagic5502
08/28/2023, 7:57 AMamagic5502
08/28/2023, 7:57 AMamagic5502
08/28/2023, 7:58 AMrp_st
08/28/2023, 7:58 AMamagic5502
08/28/2023, 8:00 AMgunicorn
with geventwebsocket.gunicorn.workers.GeventWebSocketWorker
on production envKShivendu
08/28/2023, 8:14 AMamagic5502
08/28/2023, 8:14 AMamagic5502
08/28/2023, 8:14 AMrp_st
08/28/2023, 8:15 AMKShivendu
08/28/2023, 8:31 AMamagic5502
08/28/2023, 8:32 AMgunicorn
with this executor? geventwebsocket.gunicorn.workers.GeventWebSocketWorker
KShivendu
08/28/2023, 8:34 AMamagic5502
08/28/2023, 8:44 AMrp_st
08/28/2023, 8:45 AMrp_st
08/28/2023, 8:45 AMamagic5502
08/28/2023, 8:46 AMamagic5502
08/28/2023, 8:48 AMfrom flask import Flask
from flask_cors import CORS
from dotenv import load_dotenv
from flask_sqlalchemy import SQLAlchemy
from flask_socketio import SocketIO
from sqlalchemy import create_engine
from supertokens_python import get_all_cors_headers
from app.authentication import init_supertokens
from supertokens_python.framework.flask import Middleware
from app.metrics import FlaskMetrics
from app.clients.posthog import PostHogClient
from utils.server import is_gunicorn
load_dotenv()
app = Flask("app")
socketio = SocketIO()
db = SQLAlchemy()
metrics = FlaskMetrics()
posthog_client = PostHogClient()
def create_app():
app.config.from_object('app.config.Config')
db.init_app(app)
init_supertokens(app)
posthog_client.init_app(app)
metrics.init_app(app)
Middleware(app)
CORS(app=app,
origins=[app.config.get('WEBSITE_DOMAIN', '')],
supports_credentials=True,
allow_headers=["Content-Type"] + get_all_cors_headers())
async_mode = 'gevent' if is_gunicorn() else 'threading'
socketio.init_app(app, cors_allowed_origins="*", async_mode=async_mode)
with app.app_context():
from app.routes import register_routes
register_routes(app)
create_db_if_not_exists(db.engine)
db.create_all()
return app, socketio
def create_db_if_not_exists(engine):
from sqlalchemy_utils import database_exists, create_database
if not database_exists(engine.url):
create_database(engine.url)
main.py
@any_bp.route('/', methods=['GET'])
@verify_session()
def get_database_entity_route():
return jsonify(get_database_entity) // Any database call
run this command
gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker main:app -w 1 -b 0.0.0.0:8000
rp_st
08/28/2023, 8:48 AMKShivendu
08/28/2023, 10:16 AMamagic5502
08/28/2023, 12:51 PMKShivendu
08/28/2023, 12:52 PMrp_st
08/28/2023, 12:54 PMrp_st
08/28/2023, 12:54 PMamagic5502
08/28/2023, 12:57 PMrp_st
08/28/2023, 12:58 PMrp_st
08/28/2023, 12:59 PMamagic5502
08/31/2023, 10:53 AMrp_st
08/31/2023, 10:54 AMamagic5502
08/31/2023, 10:59 AMrp_st
08/31/2023, 11:00 AMrp_st
08/31/2023, 11:00 AMmode='asgi'
.rp_st
08/31/2023, 11:00 AMwsgi
if using gunicorn
amagic5502
08/31/2023, 11:01 AMrp_st
08/31/2023, 11:02 AMamagic5502
08/31/2023, 11:03 AMrp_st
08/31/2023, 11:03 AMamagic5502
08/31/2023, 11:04 AMamagic5502
08/31/2023, 11:04 AMrp_st
08/31/2023, 11:04 AMrp_st
08/31/2023, 11:05 AMamagic5502
08/31/2023, 11:05 AMrp_st
08/31/2023, 11:05 AMamagic5502
08/31/2023, 11:07 AMrp_st
08/31/2023, 11:07 AMamagic5502
08/31/2023, 11:08 AMrp_st
08/31/2023, 11:08 AMrp_st
08/31/2023, 11:08 AMrp_st
08/31/2023, 11:08 AMamagic5502
08/31/2023, 11:09 AMrp_st
08/31/2023, 11:09 AMamagic5502
08/31/2023, 11:09 AMrp_st
08/31/2023, 11:09 AMamagic5502
08/31/2023, 11:09 AMamagic5502
08/31/2023, 11:10 AMrp_st
08/31/2023, 11:10 AMrp_st
08/31/2023, 11:10 AMamagic5502
08/31/2023, 11:11 AMName: supertokens-python
Version: 0.14.8
rp_st
08/31/2023, 11:11 AMamagic5502
08/31/2023, 11:15 AMasync_mode
when running on GUNICORN
https://discord.com/channels/603466164219281420/1145626044393594880/1145641061348286536rp_st
08/31/2023, 11:20 AMrp_st
08/31/2023, 11:21 AMrp_st
08/31/2023, 11:21 AMasyncio
.rp_st
08/31/2023, 11:21 AMnest-asyncio
, this problem will be fixed?amagic5502
08/31/2023, 11:22 AMrp_st
08/31/2023, 11:22 AMamagic5502
08/31/2023, 11:22 AMrp_st
08/31/2023, 11:22 AMamagic5502
08/31/2023, 11:23 AMrp_st
08/31/2023, 11:23 AMamagic5502
08/31/2023, 11:23 AMrp_st
08/31/2023, 11:48 AMpip install git+https://github.com/supertokens/supertokens-python.git@b4b0c4a8ad52838c7f39a5d2167e09aedc8580ac --force
We are still running our tests on it, and it should take 1-2 hoursamagic5502
08/31/2023, 11:51 AMrp_st
08/31/2023, 11:52 AMrp_st
08/31/2023, 11:55 AMamagic5502
08/31/2023, 11:59 AMrp_st
08/31/2023, 12:01 PMrp_st
08/31/2023, 12:02 PMrp_st
08/31/2023, 12:02 PMrp_st
08/31/2023, 12:02 PMrp_st
08/31/2023, 12:03 PMrp_st
08/31/2023, 12:06 PM4d20336929ce23689f27e39992d5316522c96d15
rp_st
08/31/2023, 12:07 PMpip install git+https://github.com/supertokens/supertokens-python.git@4d20336929ce23689f27e39992d5316522c96d15 --force
amagic5502
08/31/2023, 12:22 PMamagic5502
08/31/2023, 12:22 PMrp_st
08/31/2023, 12:23 PMrp_st
08/31/2023, 12:48 PMamagic5502
08/31/2023, 1:27 PMrp_st
08/31/2023, 1:27 PMamagic5502
08/31/2023, 1:55 PMamagic5502
08/31/2023, 1:55 PMamagic5502
08/31/2023, 1:56 PMrp_st
08/31/2023, 1:59 PMamagic5502
08/31/2023, 2:03 PMget_user_by_id
from syncioamagic5502
08/31/2023, 2:03 PMamagic5502
08/31/2023, 2:03 PMfrom supertokens_python.recipe.thirdpartyemailpassword.syncio import get_user_by_id
amagic5502
08/31/2023, 2:12 PMamagic5502
08/31/2023, 2:12 PMamagic5502
08/31/2023, 2:12 PMamagic5502
08/31/2023, 2:13 PMamagic5502
08/31/2023, 2:21 PMamagic5502
08/31/2023, 2:25 PMrp_st
08/31/2023, 2:31 PMrp_st
08/31/2023, 2:32 PMget_user_by_id
?rp_st
08/31/2023, 2:32 PMamagic5502
08/31/2023, 2:38 PMamagic5502
08/31/2023, 2:39 PMdef validate_is_admin():
def decorator(route_function):
@wraps(route_function)
def wrapper(*args, **kwargs):
session = g.supertokens
user_id = session.get_user_id()
user = get_user_by_id(user_id)
if (not user):
abort(401)
if user.email.endswith('@') and user.third_party_info:
return route_function(*args, **kwargs)
abort(403)
return wrapper
return decorator
rp_st
08/31/2023, 2:40 PMrp_st
08/31/2023, 2:40 PMrp_st
08/31/2023, 2:41 PMd900f065687445c058131b859b00b34143e3248b
rp_st
08/31/2023, 2:41 PMpip install git+https://github.com/supertokens/supertokens-python.git@d900f065687445c058131b859b00b34143e3248b --force
amagic5502
08/31/2023, 3:08 PMamagic5502
08/31/2023, 3:11 PMFile "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/recipe/thirdpartyemailpassword/asyncio/__init__.py", line 29, in get_user_by_id
return await ThirdPartyEmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_id(
File "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py", line 134, in get_user_by_id
tp_user = await self.tp_get_user_by_id(user_id, user_context)
File "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/recipe/thirdparty/recipe_implementation.py", line 36, in get_user_by_id
response = await self.querier.send_get_request(
File "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/querier.py", line 145, in send_get_request
return await self.__send_request_helper(path, "GET", f, len(self.__hosts))
File "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/querier.py", line 298, in __send_request_helper
raise_general_exception(e)
File "/opt/homebrew/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 25, in raise_general_exception
raise GeneralError(msg) from None
supertokens_python.exceptions.GeneralError: unknown async library, or not in async context
amagic5502
08/31/2023, 3:11 PMrp_st
08/31/2023, 3:21 PMrp_st
08/31/2023, 3:37 PMrp_st
08/31/2023, 3:37 PMpip install git+https://github.com/supertokens/supertokens-python.git@dbca4da04d3648143db567e6d327c6423593bdd9 --force
rp_st
08/31/2023, 3:49 PMamagic5502
08/31/2023, 8:13 PMamagic5502
08/31/2023, 8:14 PMbackend git:(main) pip freeze | grep super
supertokens-python @ git+https://github.com/supertokens/supertokens-python.git@dbca4da04d3648143db567e6d327c6423593bdd9e
rp_st
09/01/2023, 5:46 AMamagic5502
09/01/2023, 2:13 PMrp_st
09/01/2023, 2:19 PMamagic5502
09/01/2023, 2:21 PMamagic5502
09/02/2023, 4:47 PMrp_st
09/02/2023, 8:04 PMamagic5502
09/03/2023, 6:28 AMrp_st
09/03/2023, 6:32 AMamagic5502
09/03/2023, 6:39 AMrp_st
09/03/2023, 6:53 AMKShivendu
09/04/2023, 6:37 AMgunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 -b 0.0.0.0:3001 app:app
)amagic5502
09/04/2023, 6:45 AMKShivendu
09/04/2023, 6:50 AMamagic5502
09/04/2023, 6:51 AMamagic5502
09/04/2023, 7:11 AMerror Error: SuperTokens core threw an error for a GET request to path: '/apiversion' with status code: 502 and message: <html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
amagic5502
09/04/2023, 7:14 AMamagic5502
09/04/2023, 7:14 AMamagic5502
09/04/2023, 7:35 AMKShivendu
09/04/2023, 7:44 AMamagic5502
09/04/2023, 8:41 AMrp_st
09/04/2023, 8:42 AMrp_st
09/04/2023, 8:42 AMamagic5502
09/04/2023, 9:27 AMrp_st
09/04/2023, 9:29 AMamagic5502
09/04/2023, 9:30 AMrp_st
09/04/2023, 9:32 AMamagic5502
09/04/2023, 9:32 AMrp_st
09/04/2023, 9:34 AMrp_st
09/04/2023, 9:34 AMamagic5502
09/04/2023, 10:36 AMrp_st
09/06/2023, 7:04 AMrp_st
09/06/2023, 7:05 AMusing-nest-asyncio
and try to use that.
This is the commit hash -> 7c74be58df725168bbecaf466404e3aa0f4db967
amagic5502
09/18/2023, 1:20 PMrp_st
09/18/2023, 1:21 PM