尝试使用Google App Engine的remote_api
,以便我们可以通过IDE进行逐行调试。
远程api起初效果很好。该应用程序能够成功从数据库中检索信息。当wepapp响应客户端浏览器时会发生错误。
守则:
这与app引擎documentation中提供的示例非常相似:
from model import My_Entity
from google.appengine.ext.remote_api import remote_api_stub
# Test database calls
def get(w_self):
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func, 'myapp.appspot.com')
t_entity = My_Entity.get_by_key_name('the_key')
w_self.response.set_status(200)
# The error occurs AFTER this code executes, when webapp actually responds to the browser
错误追溯:
该错误似乎与blobstore有关。
远程api是否在代码中太晚了?
... webapp通过localhost服务器对blobstore做了什么?然后远程api可能会将请求重定向到服务器中的blobstore而不是webapp期望它的localhost调试服务器?
Traceback (most recent call last): File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2795, in _HandleRequest login_url) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3622, in CreateImplicitMatcher get_blob_storage) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_blobstore.py", line 420, in CreateUploadDispatcher return UploadDispatcher() File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_blobstore.py", line 307, in __init__ get_blob_storage()) File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_blobstore.py", line 79, in GetBlobStorage return apiproxy_stub_map.apiproxy.GetStub('blobstore').storage AttributeError: 'RemoteStub' object has no attribute 'storage'
远程api是否应该在代码中的其他位置初始化?
或者这个问题与其他问题有关吗?
非常感谢!
答案 0 :(得分:0)
要使其正常工作,您可以使用测试平台的帮助来启动缺少的存根:
ADDRESS=....
remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func, ADDRESS)
# First, create an instance of the Testbed class.
myTestBed = testbed.Testbed()
# Then activate the testbed, which prepares the service stubs for use.
myTestBed.activate()
# Next, declare which service stubs you want to use.
myTestBed.init_blobstore_stub()
myTestBed.init_logservice_stub()