使用来自appengine-utilities的会话在windows上出错 [英] Error on windows using session from appengine-utilities

查看:155
本文介绍了使用来自appengine-utilities的会话在windows上出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的项目中,我使用了一个会话处理程序( http://gaeutilities.appspot.com/session )它可以在我的Mac上正常工作,但是在我得到的窗口中:



追溯(最近一次调用最后):
文件C:\程序文件(x86)\Google\google_appengine\google\appengine\ext\\ \\ webapp_init __。py,第510行,在调用
handler.get(* groups)
文件C:\ Development \Byggmax.Affiliate\bmaffiliate\ admin.py,第29行,获取
session = Session()
文件C:\ Development \Byggmax.Affiliate\bmaffiliate\appengine_utilities\sessions.py,第547行,在 init
self.cookie.load(string_cookie)
文件C:\Python26\lib\Cookie.py,第628行,载入
代表k,v代表rawdata.items():
AttributeError:'unicode'对象没有任何属性'items'

任何熟悉Session Handler的人都知道这件事吗?所有帮助都欢迎!



.. fredrik

解决方案

虽然完全独立于操作系统,但通过查看源代码来清楚地看到它。在 sessions.py 第544-547行:

  string_cookie = os.environ.get(uHTTP_COOKIE,u)
self.cookie = Cookie .SimpleCookie()
self.output_cookie = Cookie.SimpleCookie()
self.cookie.load(string_cookie)

第544行很可能使得 string_cookie 是unicode(尽管它可能是来自环境的字节字符串,那些 ü表示 sessions.py 作者正在努力将其作为unicode! - )。同时在 Cookie.py 第624-628行:

  if type(rawdata)== type():
self .__ ParseString(rawdata)
else:
#self.update()不会调用我们的自定义__setitem__
for k,v in rawdata.items():
字节字符串:其他任何内容(包括unicode字符串!)都被视为字典(因此崩溃)。



很显然,Cookie.py着重于而非这个sessions.py的开发目的。那么可能发生了什么......?那么,我们当然知道App Engine是严格的Python 2.5,我们展示的Cookie.py是Python 2.6。所以我们来看看2.5中的Cookie.py(这个版本中的第618-621行):

  if type(rawdata)==类型():
self .__ ParseString(rawdata)
else:
self.update(rawdata)

所以在2.5中,给定一个空unicode字符串,cookie(子类字典)不会执行 self.update(u'') ...这是一个无害的无操作。 2.6中的注释说明了为什么Cookie.py的维护者切换到当前循环......当rawdata的 u''



长话短说:在Windows机器上安装Python 2.5,并使用GAE SDK的那个版本, ,而不是<2.6> - 除非你真的很喜欢调试非常微妙的版本差异,其中一个不正确的使用在2.5中无害,但在2.6中打破,就像这样;-)。同样在gabutilities跟踪器中输入一个bug,因为使用空unicode字符串调用 load 是完全错误的,尽管在2.5版中它恰好是无害的。 p>

具体来说,从此处,具体取决于您是否拥有32位或64位版本的Windows。


I ran across an odd problem while trying to transfer a project to a windows machine.

In my project I use a session handler (http://gaeutilities.appspot.com/session) it works fine on my mac but on windows I get:

Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp__init__.py", line 510, in call handler.get(*groups) File "C:\Development\Byggmax.Affiliate\bmaffiliate\admin.py", line 29, in get session = Session() File "C:\Development\Byggmax.Affiliate\bmaffiliate\appengine_utilities\sessions.py", line 547, in init self.cookie.load(string_cookie) File "C:\Python26\lib\Cookie.py", line 628, in load for k, v in rawdata.items(): AttributeError: 'unicode' object has no attribute 'items'

Anyone familiar with the Session Handler that knows anything of this? All help are welcome!

..fredrik

解决方案

The bug is pretty clear by glancing at the sources, although perfectly OS-independent. In sessions.py lines 544-547:

    string_cookie = os.environ.get(u"HTTP_COOKIE", u"")
    self.cookie = Cookie.SimpleCookie()
    self.output_cookie = Cookie.SimpleCookie()
    self.cookie.load(string_cookie)

lines 544 makes it very likely that string_cookie is unicode (though it might be a byte string from the environment, those u"" mean that the sessions.py author is trying hard to get it as unicode!-). Meanwhile in Cookie.py lines 624-628:

if type(rawdata) == type(""):
    self.__ParseString(rawdata)
else:
    # self.update() wouldn't call our custom __setitem__
    for k, v in rawdata.items():

line 624 only parses a byte string: anything else (including a unicode string!) is treated like a dict (whence the crash).

Obviously this Cookie.py is emphatically not the one this sessions.py was developed for. So what can possibly have happened...? Well, we do know of course that App Engine is strictly Python 2.5 and the Cookie.py we showed is that of Python 2.6. So let's look at Cookie.py in 2.5 (lines 618-621 in this version):

    if type(rawdata) == type(""):
        self.__ParseString(rawdata)
    else:
        self.update(rawdata)

so in 2.5, given an empty unicode string, the cookie (which subclasses dict) does self.update(u'')... which is an innocuous no-op. The comment in 2.6 shows why the maintainer of Cookie.py switched to the current loop... which breaks when rawdata's u''.

Long story short: install Python 2.5 on your Windows machine, and use that version with the GAE SDK, not the 2.6 you're currently using -- unless you truly love debugging of extremely subtle version differences where an incorrect use was innocuous in 2.5 but breaks in 2.6, like this one;-). Also enter a bug about this in the gaeutilities tracker, since that call to load with an empty unicode string is simply wrong, even though in 2.5 it happens to be innocuous.

Specifically, get the appropriate Windows msi of 2.5.4 from here, depending on whether you have a 32-bit or 64-bit version of Windows.

这篇关于使用来自appengine-utilities的会话在windows上出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆