相關部分:谷歌AppEngine上告訴我,我的int是不是代碼的一個int
pk = int(pk)
logging.info('pk: %r :: %s', pk, type(pk))
instance = models.Model.get_by_id(int(pk))
從日誌消息輸出上述
pk: 757347 :: <type 'int'>
堆棧跟蹤:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 634, in __call__
handler.get(*groups)
File "/base/data/home/apps/<myapp>/<version>/scrape.py", line 61, in get
instance = models.Model.get_by_id(int(pk))
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1212, in get_by_id
return get(keys[0], config=config)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1434, in get
model = cls1.from_entity(entity)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1350, in from_entity
instance = cls(None, _from_entity=True, **entity_values)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 890, in __init__
prop.__set__(self, value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 593, in __set__
value = self.validate(value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 2967, in validate
% (self.name, type(value).__name__))
BadValueError: Property pk must be an int or long, not a unicode
如果我在這裏做錯了什麼,任何人都有想法嗎?
注:去除代碼的最後一行int
沒有區別(這是第一個版本)。
另外,代碼在dev_appserver.py
上沒有問題。
我覺得問題不在最後一行。它在logging.info – 2011-04-14 09:05:57
對不起,問題不在於日誌記錄。你確定數據存儲中存在具有757347 ID的實體嗎? – 2011-04-14 09:21:52
@Abdul Kader:如果該項不存在,它應該返回「無」。但我嘗試刪除實體,並沒有任何區別。 – Wolph 2011-04-14 11:34:51