gpt4 book ai didi

python - App Engine 1.8.4 引发 AttributeError 将文档放入搜索索引

转载 作者:行者123 更新时间:2023-11-28 17:45:29 25 4
gpt4 key购买 nike

我一直在使用 App Engine API 的 1.8.1 版本,因为在更高版本中远程 API 存在已知问题。在尝试最新的 1.8.4 时,我遇到了一个错误,代码在 1.8.1 中运行良好,但现在无法尝试将文档添加到搜索索引:

Traceback (most recent call last):
File "~/tools/devappserver2/api_server.py",
62, in _handle_POST
api_response = _execute_request(request).Encode()
File "~/tools/devappserver2/api_server.py", line 1
23, in _execute_request
make_request()
File "~/tools/devappserver2/api_server.py", line 1
15, in make_request
request_id)
File "~/google/appengine/api/apiproxy_stub.py", line 130, in MakeSy
ncCall
method(request, response)
File "~/google/appengine/api/search/simple_search_stub.py", line 65
4, in _Dynamic_IndexDocument
index.IndexDocuments(params.document_list(), response)
File "~/google/appengine/api/search/simple_search_stub.py", line 40
4, in IndexDocuments
self._inverted_index.AddDocument(doc_id, document)
File "~/google/appengine/api/search/simple_search_stub.py", line 30
3, in AddDocument
self._AddFieldType(field.name(), field.value().type())
File "~/google/appengine/api/search/simple_search_stub.py", line 28
9, in _AddFieldType
self._schema.AddFieldType(name, field_type)
AttributeError: 'dict' object has no attribute 'AddFieldType'

ERROR 2013-09-14 22:31:45,132 webapp2.py:1552] AttributeError("'dict' object has no attribute 'Ad
dFieldType'",)
Traceback (most recent call last):
File "~/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "~/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "~/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispat
cher
return route.handler_adapter(request, response)
File "~/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "~/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "~/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "~/docroot/update.py", line 49, in get
booking.add_to_search_index()
File "~/docroot/booking.py", line 94, in add_to_search_index
index.put(booking_full_text_document)
File "~/google/appengine/api/search/search.py", line 2506, in put
response)
File "~/google/appengine/api/apiproxy_stub_map.py", line 94, in Mak
eSyncCall
return stubmap.MakeSyncCall(service, call, request, response)
File "~/google/appengine/api/apiproxy_stub_map.py", line 328, in Ma
keSyncCall
rpc.CheckSuccess()
File "~/google/appengine/api/apiproxy_rpc.py", line 156, in _WaitIm
pl
self.request, self.response)
File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
00, in MakeSyncCall
self._MakeRealSyncCall(service, call, request, response)
File "~/google/appengine/ext/remote_api/remote_api_stub.py", line 2
34, in _MakeRealSyncCall
raise pickle.loads(response_pb.exception())
RuntimeError: AttributeError("'dict' object has no attribute 'AddFieldType'",)
INFO 2013-09-14 22:31:45,145 module.py:593] default: "GET /update/somekey/someparamter/value HTTP/1.1" 500 2
691

负责的代码部分:

from google.appengine.ext import ndb
from google.appengine.api import search
import logging

class Booking(ndb.Model):

timestamp = ndb.DateTimeProperty(auto_now_add=True)
last_modified = ndb.DateTimeProperty(auto_now=True)

field1 = ndb.StringProperty()
field2 = ndb.StringProperty()
#etc...

def add_to_search_index(self):

list_of_full_text_fields = [
'field1',
'field2',
]

full_text_data = []

for field in list_of_full_text_fields:

full_text_data.append(unicode(getattr(self, field)))

full_text_data = ' '.join(full_text_data)

full_text_document = search.Document(

doc_id = self.key.urlsafe(),
fields=[
search.TextField(
name='f',
value=full_text_data
),
]
)

try:
index = search.Index(name="fullText")
index.put(full_text_document)
except search.Error:
logging.exception('Put failed')

最佳答案

会不会是那些版本的 API 发生了变化?

版本 1.8.3 - 2013 年 8 月 6 日发布了对搜索 API 文档的重大重写。请参阅:https://developers.google.com/appengine/docs/python/search/

或错误修复..

版本 1.8.4 - 2013 年 9 月 9 日修复了与搜索 API 中的表达式相关的 unicode 问题。在包含 unicode 字符的文档上使用片段字段进行搜索失败。

http://code.google.com/p/googleappengine/wiki/SdkReleaseNotes

关于python - App Engine 1.8.4 引发 AttributeError 将文档放入搜索索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18807214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com