簡體   English   中英

不能在谷歌appengine的實時實例上寫cookie

[英]Cant write cookies on live instance of google appengine

我一直在努力將我們的一個應用程序轉換為線程安全。 在本地開發應用服務器上進行測試時,一切都按預期工作。 但是,在部署應用程序時,似乎沒有正確編寫Cookie?

在日志中有一個沒有堆棧跟蹤的錯誤:

2012-11-27 16:14:16.879 Set-Cookie: idd_SRP=Uyd7InRpbnlJZCI6ICJXNFdYQ1ZITSJ9JwpwMAou.Q6vNs9vGR-rmg0FkAa_P1PGBD94; expires=Wed, 28-Nov-2012 23:59:59 GMT; Path=/ 

這是有問題的代碼塊:

# area of the code the emits the cookie
cookie = Cookie.SimpleCookie()
if not domain:
    domain = self.__domain
self.__updateCookie(cookie, expires=expires, domain=domain)
self.__updateSessionCookie(cookie, domain=domain)
print cookie.output()

Cookie助手方法:

def __updateCookie(self, cookie, expires=None, domain=None):
    """
    Takes a Cookie.SessionCookie instance an updates it with all of the
    private persistent cookie data, expiry and domain.

    @param cookie: a Cookie.SimpleCookie instance
    @param expires: a datetime.datetime instance to use for expiry
    @param domain: a string to use for the cookie domain
    """

    cookieValue = AccountCookieManager.CookieHelper.toString(self.cookie)
    cookieName = str(AccountCookieManager.COOKIE_KEY % self.partner.pid)

    cookie[cookieName] = cookieValue
    cookie[cookieName]['path'] = '/'
    cookie[cookieName]['domain'] = domain

    if not expires:
        # set the expiry date to 1 day from now
        expires = datetime.date.today() + datetime.timedelta(days = 1)

    expiryDate = expires.strftime("%a, %d-%b-%Y 23:59:59 GMT")
    cookie[cookieName]['expires'] = expiryDate

def __updateSessionCookie(self, cookie, domain=None):
    """
    Takes a Cookie.SessionCookie instance an updates it with all of the 
    private session cookie data and domain.

    @param cookie: a Cookie.SimpleCookie instance
    @param expires: a datetime.datetime instance to use for expiry
    @param domain: a string to use for the cookie domain
    """

    cookieValue = AccountCookieManager.CookieHelper.toString(self.sessionCookie)
    cookieName = str(AccountCookieManager.SESSION_COOKIE_KEY % self.partner.pid)

    cookie[cookieName] = cookieValue
    cookie[cookieName]['path'] = '/'
    cookie[cookieName]['domain'] = domain

同樣,使用的庫是:

  • Python 2.7
  • Django 1.2

關於我可以嘗試什么的任何建議?

我看到了創建cookie的代碼,但實際上你是否將它附加到響應中?

你應該在某處有一個response.set_cookie()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM