在 google app engine 上使用 urlfetch 时我的代码错误在哪里

发布于 2024-09-30 06:04:18 字数 1167 浏览 0 评论 0原文

这是我的代码:

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 -

所以我找不到错误,

你是吗?

谢谢

this is my code:

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('/')

and the error is :

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 -

so i cant find the error ,

did you .

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×眷恋的温暖 2024-10-07 06:04:18

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

You're attempting to store the result into counter.ajax, which is a StringProperty that does not have multiline=True. Either set multiline=True in the definition of 'ajax', or replace it with a TextProperty(). The latter is almost certainly the correct answer - TextProperties can be longer, and aren't indexed.

離殇 2024-10-07 06:04:18

错误出在您的计数器模型中。

“ajax”需要是多行字符串属性。请参阅类型和属性类文档

您需要执行以下操作:

ajax = db.StringProperty(multiline=True)

另请注意,db.StringProperty 只能用于 500 个字符或更少的字符串。

The error is in your Counter model.

"ajax" needs to be a multiline string property. See the Types and Property Classes documentation.

You'll want to do:

ajax = db.StringProperty(multiline=True)

Also note that db.StringProperty can only be used for strings of 500 characters or less.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文