问题描述
我已经使用SQLAlchemy开发了一个Flask应用程序,该应用程序连接到Snowflake DB作为后端.如果网站闲置超过4小时,我就遇到了Snowflake身份验证令牌过期的问题.我在Google上浏览后找到了答案
I have developed a Flask application connecting to Snowflake DB as the backend using SQLAlchemy. I ran into Snowflake authentication token expired issue if the website remains idle for more than 4 hrs. I looked over in Google and found an answer
https://github.com/snowflakedb/gosnowflake/issues/160
,但对于Snowflake-SQLAlchemy似乎无效.
but it doesn't seem valid for Snowflake-SQLAlchemy.
我使用APScheduler实现了心跳代码,该代码每50分钟触发一次选择1",但是如果会话在浏览器(SSO)中处于活动状态,则会引发身份验证令牌已过期"错误.
I implemented a heartbeat code using APScheduler which fires "Select 1" every 50 mins but if the session is active in the browser (SSO) it throws "Authentication token has expired" error.
from sqlalchemy import create_engine
engine = create_engine('snowflake://<connection-string>' )
connection = engine.connect()
names = connection.execute_query("select names from employees")
def sensor():
""" Function for scheduling purposes. """
v = cursor.execute("""select 1""")
v = v.fetchall()
print(v)
sched = BackgroundScheduler(daemon=True)
sched.add_job(sensor,'interval',minutes=50)
sched.start()
推荐答案
https://docs.snowflake.net/manuals/sql-reference/parameters.html#client-session-keep-alive
尝试客户端会话保持活动状态以保持会话活动.
Try Client Session Keep Alive to keep the session active.
这篇关于Snowflake身份验证令牌已过期(390114)-Snowflake-SQLAlchemy是否有心跳代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!