我无法使用cherrypy检索cookie:问题是什么?

问题描述

我正在一个网页上,我想保存cookie。我可以将它们设置为as shown in the image。但是,当我尝试请求他们时,我只会获得会话ID。这是我设置它们时的打印件:

Set-Cookie: confirm=True 
Set-Cookie: role=resercher
Set-Cookie: session_id=49c5ae1aee547fe542d6a93c276331f038a89591; expires=Fri,16 Oct 2020 10:53:08 GMT; Max-Age=3600; Path=/
Set-Cookie: token=T7QrDqRLV0
Set-Cookie: uname=sato96

这是我设置它们的方式:

            cookie = cherrypy.response.cookie
            cookie["uname"] = dati["uname"]
            cookie["token"] = token
            u="reposleep"+dati["uname"]
            cookie["confirm"] = self.uh.reference[u]["confirm"]
            cookie["role"] = self.uh.reference[u]["role"]
            print(cookie)
            if token!="":
                cherrypy.response.cookie["uname"]['max-age']=3600*24*7
                cherrypy.response.cookie["token"]['max-age']=3600*24*7
                cherrypy.response.cookie["confirm"]['max-age']=3600*24*7
                cherrypy.response.cookie["role"]['max-age']=3600*24*

然后这是我尝试检索它们的方:

                cookies = cherrypy.request.cookie
                print(cookies["session_id"])
                
                try:
                    token = cookies["token"].value
                    uname = cookies["uname"].value
                    print(token)
                    print(uname)
                    ans=self.remember(token,uname)
                    print(ans)
                    if ans == True:
                        #setto di nuovo i tempi dei cookie
                        cherrypy.response.cookie["uname"]['max-age']=3600*24*7
                        cherrypy.response.cookie["token"]['max-age']=3600*24*7
                        cherrypy.response.cookie["role"]['max-age']=3600*24*7
                        cherrypy.response.cookie["confirm"]['max-age']=3600*24*7
                        s="Download.html"
                    else:
                        s="Login.html"
                except:
                    s="Login.html"

如果我尝试删除try语句,则会得到一个关键错误:实际上,当我打印“ cookie”变量时,我会得到一个具有单个键的字典:session_id。 有人可以帮助我吗?我不知道如何解决这个问题。我不知道我会遇到什么样的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)