LPTHW EX52 question on session_sample.py

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):
        return ""

if __name__ == "__main__":

The message on PowerShell is

PS E:\yiliang\python\projects\gothonweb> python session_sample.py - - [08/Apr/2020 16:02:42] “HTTP/1.1 GET /” - 404 Not Found - - [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
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?

I fixed your code block. When you post code do this:

# code here

Or do this:

# your code here

Now, as for what’s broken, it looks like the file you’re trying to write to either exists, or you don’t have permission to write to it. I suspect the DiskStore(‘sessions’) is trying to use a file named ‘sessions’ but that file exists, or is a directory and shouldn’t be, or is a file and it wants to make a directory.

I tried to uninstall lpthw.web and reinstall again. It fixed the problem now… after 10 hours trying and struggling. I got this feeling after a sleep.

That makes me feel wonder if I am stupid about coding. :sweat_smile::laughing:

Ha! No you’re not stupid. pip is stupid. I’m curious what it did but I’m guessing you figured it out so should be good to go.