Hi
When I tried session_sample.py in EX52 and used browser open http://localhost:8080/count
it shows 1. However, after refresh, it shows “internal server error”
The session_sample.py is
import web
web.config.debug = False
urls = (
"/count", "count",
"/reset", "reset"
)
app = web.application(urls, locals())
store = web.session.DiskStore('sessions')
session = web.session.Session(app, store, initializer={'count': 0})
class count:
def GET(self):
session.count += 1
return str(session.count)
class reset:
def GET(self):
session.kill()
return ""
if __name__ == "__main__":
app.run()
The message on PowerShell is
================================================================
PS E:\yiliang\python\projects\gothonweb> python session_sample.py
http://0.0.0.0:8080/
127.0.0.1:49703 - - [08/Apr/2020 16:02:42] “HTTP/1.1 GET /” - 404 Not Found
127.0.0.1:49703 - - [08/Apr/2020 16:02:48] “HTTP/1.1 GET /count” - 200 OK
Traceback (most recent call last):
File “C:\Python27\lib\site-packages\web\application.py”, line 287, in process
return p(lambda: process(processors))
File “C:\Python27\lib\site-packages\web\session.py”, line 102, in _processor
self._save()
File “C:\Python27\lib\site-packages\web\session.py”, line 151, in _save
self.store[self.session_id] = dict(self._data)
File “C:\Python27\lib\site-packages\web\session.py”, line 298, in setitem
os.rename(tname, path) # atomary operation
WindowsError: [Error 183] 當檔案已存在時,無法建立該檔案。
The Traditional Chinese in windows error means: “when the file exists, cannot create the file.”
Could anyone let me know why?