Completely solve the problem of saving session in file mode of webpy framework on SAE
#app = web.application(urls, globals()).wsgifunc()
app = web.application(urls, globals())
#application = sae.create_wsgi_app(app)
application = sae.create_wsgi_app(app.wsgifunc())
Commenting out the code is the sample code provided by the official, but the official code directly calls wsgifunc() when the APP is instantiated for convenience, but this will cause the calling error of some webpy attributes. For example, the failure of calling app.add_processor.
2, set the call of the global session
# session , session web.config
if web.config.get('_session') is None:
shop_session = web.session.Session(app, DiskStore(session_root),
initializer={'login_shop_id':'NULL'})
web.config._session = shop_session
else:
shop_session = web.config._session
def session_hook():
web.ctx.session = shop_session
app.add_processor(web.loadhook(session_hook))
3. Solve the problem that the local directory cannot be read and written in the sae environmentIn the SAE environment, python cannot read and write to the local directory, but sae provides Storage, and Storage can be mounted and used like a local disk. So add the following code:
monkey.patch_all()
session_root = '/s/session/'
Note: Storage needs to be enabled in sae in advance, and add "domain: session"in order to have permissions.
4, Solve the problem that SEA's Storage is mounted as a disk but does not support the os.remove method
"The currently supported (patch) file system interface functions are: open, os.listdir, os.mkdir, os.path.exists, os.path.isdir, os.open, os.fdopen, os.close, os.chmod , os.stat, os.unlink, os.rmdir"but webpy calls os.remove in the DiskStore.cleanup method, which needs to be changed to os.unlink
# SAE stroge os.remove ,
class DiskStore(web.session.DiskStore):
def __init__(self, root):
web.session.DiskStore.__init__(self, root)
# if the storage root doesn't exists, create it.
# self.root = root
def __delitem__(self, key):
path = self._get_path(key)
if os.path.exists(path):
os.unlink(path)
def cleanup(self, timeout):
now = time.time()
for f in os.listdir(self.root):
path = self._get_path(f)
atime = os.stat(path).st_atime
if now - atime > timeout :
os.unlink(path)# unlink
OK, now the session can be used normally.
editor by [email protected] Welcome to reprint, please indicate the source
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.