我在谷歌应用引擎上使用urlfetch的代码错误在哪里

zjm*_*126 0 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:
            counter.ajax = result.content
            counter.put()

        self.redirect('/')
Run Code Online (Sandbox Code Playgroud)

而错误是:

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 -
Run Code Online (Sandbox Code Playgroud)

所以我找不到错误,

你是否 .

谢谢

Nic*_*son 5

您试图将结果存储到counter.ajax中,这是一个没有multiline = True的StringProperty.在'ajax'的定义中设置multiline = True,或者用TextProperty()替换它.后者几乎肯定是正确的答案 - TextProperties可以更长,而且没有索引.