简体   繁体   English

Google App Engine Python搜索API文档错误

[英]Google App Engine Python Search API Document Error

I'm using the Python 1.6.6 SDK and having trouble getting the search API to initialise a new Document: 我正在使用Python 1.6.6 SDK,但无法获取搜索API来初始化新文档:

from google.appengine.api import search

def index_document(document_id, some_string):
    return search.Document(
        doc_id=document_id,
        fields=[
            search.TextField(name='text_field', value=some_string),
            search.DateField(name='date', value=datetime.now().date())
        ])

In response I get: 作为回应,我得到:

AttributeError: type object 'search' has no attribute 'Document'

I can't see any evidence that this is a general problem, and all the docs point to this being the procedure for initialising a Document. 我看不到任何证据表明这是一个普遍的问题,所有文档都指出这是初始化文档的过程。

However, if I place the API call within the function it executes as expected: 但是,如果将API调用放在函数中,它将按预期执行:

def index_document(document_id, some_string):

    from google.appengine.api import search

    return search.Document(...

I can't see any reason why this would work, but a global import wouldn't as I am importing a number of their APIs. 我看不到有什么理由能奏效,但是由于我要导入许多API,因此无法进行全局导入。 Has anyone had a similar problem/success in getting it to work? 有没有人在使其工作上有类似的问题/成功?

检查是否没有其他相同名称的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM