将会话传递给 backgroundTask cherrypy
Passing session to backgroundTask cherrypy
我在为我的后台任务正确配置函数以接收 cherrypy 时遇到问题。我希望后台任务使用会话数据,能够重新生成当前会话并使会话过期。
这是我正在尝试的示例
import cherrypy
import cherrypy.process.plugins
class MainApp(object):
def signin(self,user,pass):
cherrypy.session['username'] = username
cherrypy.session['password'] = password
def communicateWithServer(self):
user = cherrypy.session.get('username')
password = cherrypy.session.get('password')
response = requests.get("http://someserver/api?username="+user+"&password="+password)
cherrypy.process.plugins.BackgroundTask(600, communicateWithServer (object)).start()
但是我得到了这个错误
Traceback (most recent call last):
File "main.py", line 34, in <module>
class MainApp(object):
File "main.py", line 202, in MainApp
cherrypy.process.plugins.BackgroundTask(600, communicateWithServer(object)).start()
File "main.py", line 191, in loginReport
user = cherrypy.session.get('username')
AttributeError: 'module' object has no attribute 'session'
将会话传递给 backgroundTask 的正确方法是什么?
由于会话不能像我最初打算的那样使用,所以我正在使用 sqlite3 数据库来存储本来应该在会话中的数据,然后从那里与服务器通信。
我在为我的后台任务正确配置函数以接收 cherrypy 时遇到问题。我希望后台任务使用会话数据,能够重新生成当前会话并使会话过期。
这是我正在尝试的示例
import cherrypy
import cherrypy.process.plugins
class MainApp(object):
def signin(self,user,pass):
cherrypy.session['username'] = username
cherrypy.session['password'] = password
def communicateWithServer(self):
user = cherrypy.session.get('username')
password = cherrypy.session.get('password')
response = requests.get("http://someserver/api?username="+user+"&password="+password)
cherrypy.process.plugins.BackgroundTask(600, communicateWithServer (object)).start()
但是我得到了这个错误
Traceback (most recent call last):
File "main.py", line 34, in <module>
class MainApp(object):
File "main.py", line 202, in MainApp
cherrypy.process.plugins.BackgroundTask(600, communicateWithServer(object)).start()
File "main.py", line 191, in loginReport
user = cherrypy.session.get('username')
AttributeError: 'module' object has no attribute 'session'
将会话传递给 backgroundTask 的正确方法是什么?
由于会话不能像我最初打算的那样使用,所以我正在使用 sqlite3 数据库来存储本来应该在会话中的数据,然后从那里与服务器通信。