Webpy's session is saved and loaded automatically on every request, can you show the code that doesn't work?
On Feb 8, 10:50 pm, Oetzi <[email protected]> wrote: > I am now but it still doesn't seem to be working. Should I call > _save() on the session when I increment to keep everything sycned? > > On Feb 8, 3:01 pm, andrei <[email protected]> wrote: > > > > > I've never had any trouble with mod_wsgi. The problem may be in your > > sessions code. Why don't you use webpy session class? > > > On Feb 8, 4:46 am, Oetzi <[email protected]> wrote: > > > > Hey all, > > > > I was wondering if someone would be able to help me with a problem > > > that is driving me mad. > > > Here is my script: > > > > #!/usr/local/bin/python2.6 > > > import cgitb; cgitb.enable() > > > import sys > > > import web, os, random, time, sqlite3 > > > > def cgidebugerror(): > > > > _wrappedstdout = sys.stdout > > > > sys.stdout = web._oldstdout > > > cgitb.handler() > > > > sys.stdout = _wrappedstdout > > > > web.internalerror = cgidebugerror > > > > urls = ('/', 'upload', > > > '/progress+', 'progress', > > > '/file+', 'fileServe', > > > '/admin', 'admin') > > > > #db = web.database(dbn='sqlite', db='filedb') > > > render = web.template.render('/home/oetzi/webapps/mod/htdocs/ > > > templates/') > > > > sessions = {} > > > prog = 0 > > > up = 0 > > > > class session: > > > > def __init__(self): > > > > self.progress = 0 > > > self.title = "" > > > self.finished = False > > > > def advance(self): > > > > self.progress = self.progress + 1 > > > > class fileServe: > > > > def GET(self): > > > > arg = web.input(arg=None) > > > keys = {} > > > keys['key'] = arg.key > > > path = db.select('files', keys, what='path', > > > where='key=$key') > > > > #if not path: > > > > # return "This file doesn't seem to exist..." > > > > try: > > > > download = open(path[0].path, 'r') > > > > except IndexError: > > > > return "This file doesn't seem to exist..." > > > > web.header('Content-type', 'application/file') > > > return download.read() > > > > class upload: > > > > paths = {} > > > > def GET(self): > > > > global sessions > > > > #render html file > > > code = 0 > > > > while sessions.has_key(str(code)): > > > > code = random.randint(0, 10000000000000) > > > > newSesh = session() > > > sessions[str(code)] = newSesh > > > > return render.index(code) > > > > def POST(self): > > > > global sessions > > > global up > > > > #upload file from form > > > submit = web.input(myfile={}) > > > > code = submit.code > > > fileU = submit.myfile > > > > up = sessions[code] > > > > filepath = fileU.filename.replace('\\','/') > > > name = filepath.split('/')[-1] > > > path = '/home/oetzi/webapps/mod/htdocs/files/' + name > > > upload.paths[code] = "/file?key=" + name > > > > out = open(path, 'wb', 1000) > > > > while (True): > > > > packet = fileU.file.read(1000) > > > sessions[code].advance() > > > > if not packet: > > > > break > > > > else: > > > > out.write(packet) > > > > out.close() > > > > #block until client has been updated > > > while not sessions[code].finished: > > > > sessions[code].progress = -1 > > > > #commit to db > > > title = sessions[code].title > > > #db.insert('files', title=title, key=name, path=path) > > > > #clean up > > > sessions.pop(code) > > > path = "http://oetzi.webfactional.com" + > > > upload.paths.pop(code) > > > > return title + ": " + path > > > > class progress: > > > > def GET(self): > > > > global sessions > > > global prog > > > > #take in current title and status for user with code and > > > return > > > progress > > > arg = web.input(arg=None) > > > code = arg.code > > > prog = sessions[code] > > > > if int(arg.status) > 0: > > > > sessions[code].title = arg.title > > > path = str(upload.paths[code]) > > > sessions[code].finished = True > > > return path > > > > return sessions[code].progress > > > > def POST(self): > > > > pass > > > > class admin: > > > > def GET(self): > > > > global prog > > > global up > > > > return prog == up > > > > app = web.application(urls, globals(), autoreload=False) > > > application = app.wsgifunc() > > > > I basically upload a file using a post request from a form and then > > > update the progress based on the amount of bytes upload. For some > > > reason when I run this on my mod_wsgi server the progress fails to > > > increase on an upload. It seems as if the GET request I use to get the > > > progress and the POST request that increments the progress are using > > > different objects. Does anybody have any idea what is happening? -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
