Python 在谷歌应用程序引擎上使用urlfetch时,我的代码错误在哪里
这是我的代码:Python 在谷歌应用程序引擎上使用urlfetch时,我的代码错误在哪里,python,google-app-engine,urlfetch,Python,Google App Engine,Urlfetch,这是我的代码: class save(BaseRequestHandler): def get(self): counter = Counter.get_by_key_name('aa-s') counter.count += 1 url = "http://www.google.com" result = urlfetch.fetch(url) if result.status_code == 200:
class save(BaseRequestHandler):
def get(self):
counter = Counter.get_by_key_name('aa-s')
counter.count += 1
url = "http://www.google.com"
result = urlfetch.fetch(url)
if result.status_code == 200:
counter.ajax = result.content
counter.put()
self.redirect('/')
错误是:
Traceback (most recent call last):
File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 511, in __call__
handler.get(*groups)
File "F:\ss\Task Queue\main.py", line 48, in get
counter.ajax = result.content
File "D:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 542, in __set__
value = self.validate(value)
File "D:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 2453, in validate
raise BadValueError('Property %s is not multi-line' % self.name)
BadValueError: Property ajax is not multi-line
INFO 2010-11-04 08:24:29,905 dev_appserver.py:3283] "GET /save HTTP/1.1" 500 -
所以我找不到错误
是的
谢谢错误在您的计数器型号中 ajax需要是一个多行字符串属性。看 您将要执行以下操作:
ajax = db.StringProperty(multiline=True)
还要注意,db.StringProperty只能用于500个字符或更少的字符串。您正在尝试将结果存储到counter.ajax中,这是一个StringProperty,没有multiline=True。在“ajax”的定义中设置multiline=True,或者将其替换为TextProperty。后者几乎可以肯定是正确的答案——TextProperties可以更长,并且没有索引