使用App Engine的Remote_api配置 [英] Remote_api configuration with App Engine
问题描述
使用Python,我试图连接到我的AppEngine应用程序的remote_api处理程序,但我一直收到错误。我想要做的就是设置remote_api存根,通过它来路由数据库调用,并直接访问我的应用程序的数据存储区。因此,首先,我导入remote_api库,然后调用存根模块上的ConfigureRemoteApi,并尝试使用对远程数据存储库的调用。以下是一些示例代码:
from google.appengine.ext.remote_api import remote_api_stub
def test_remote_api( ):
#当我想使用远程api而不是本地数据存储区访问时调用此函数
remote_api_stub.ConfigureRemoteApi('myapp.appspot.com','/ _ah / remote_api',auth_func, '')
def auth_func:
#这实际上会返回一个带有凭证的元组来跳过控制台输入
return('username','password')
好的,现在我已使用remote_api_shell.py测试了我的登录信息和应用程序名称,但出现错误像这样:
文件C:\程序文件(x86)\Google\google_appengine\google\appengine \tools\dev_appserver_blobstore.py,第79行,在GetBlobStorage
返回apiproxy_stub_map.apiproxy.GetStub('blobstore')。storage
AttributeError:'RemoteStub'对象没有attr ibute'storage'
然后我得到404:Not Found from应用程序,我知道因为从Web上访问应用程序确实会给我带来结果,所以错了。我需要做什么来设置remote_api_stub,这样我不会得到这个错误?
谢谢!
您的app_id可能是错误的,并且您还需要通过解决方案
地址参数。我读了一段时间后读到了oreilly的书(书被严重过时了,不推荐)
def attach_to_app(app_id,user = None,password = None,path = None,address = None):
连接到地址处的app_id实例(默认值:< app_id> .appspot.com)
如果您未指定用户/密码,则会提示您输入一个
,如果您未指定地址,则假定为
< b< ; app_id> .appspot.com
path:指向remote_api处理程序的路径,如果没有指定
,将使用/ _ah / remote_api
path =路径或者/ _ah / remote_api
如果不是地址:
address =%s.appspot.com%app_id
$ init_remote_api(app_id,路径,地址,用户=用户,密码=密码)
$ b def auth_func():
函数提示用户输入凭证
email_address = raw_input(Emai l地址:)
password = getpass.getpass(Password:)
返回email_address,密码
def init_remote_api(app_id,path,address,user = None,password = None):
通用包装函数初始化给定路径的remoteapi
required
======== =
app_id:连接到
的应用程序的app_id path:remote_api处理程序的路径ex:/ _ah / remote_api
地址:连接到ex的服务器:myapp.appspot.com
如果未指定用户名和密码,则会在
连接时提示您是否需要
如果用户和密码:
def my_auth ):
return(user,password)
else:
my_auth = auth_func
remote_api_stub.ConfigureRemoteApi(app_id,path,my_auth,address)
remote_api_stub .MaybeInvokeAuthentication()
os.environ [SERVER_SOFTWARE] =开发(remote_api)/1.0
#e xample
APP_ID =s〜myapp#当hrds被引入时,有必要指定app_id和地址附注s〜...
ADDRESS =myapp.appspot.com
attach_to_app(APP_ID,address = ADDRESS)
Using Python, I'm trying to connect to my AppEngine app's remote_api handler, but I keep getting an error. What I want to do is set up the remote_api stubs to route database calls through that and access my app's datastore directly. So, first, I import the remote_api libraries, then call the ConfigureRemoteApi on the stub module, and try to use the calls to the remote datastore. Here's some sample code:
from google.appengine.ext.remote_api import remote_api_stub
def test_remote_api():
# This function is called when I want to use the remote api instead of the local datastore access
remote_api_stub.ConfigureRemoteApi('myapp.appspot.com', '/_ah/remote_api', auth_func, '')
def auth_func:
# This actually returns a tuple with my credentials to skip the console input
return ('username', 'password')
Ok, now, I've tested my login information and the app name with remote_api_shell.py, but I get an error like this:
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'
And then I get a 404: Not Found from the application, which I know to be wrong since accessing the app from the Web does give me the result. What do I need to do to set up the remote_api_stub so I won't get this error?
Thanks!
assuming you are using high replication datastore now...
Your app_id is probably wrong, and you also need to pass the address parameter. I whipped this up a while back while reading the oreilly book for appengine(book is severely out of date and not recommended)
def attach_to_app(app_id, user=None, password=None, path=None, address=None):
"""
attaches to app_id instance at address (default: <app_id>.appspot.com)
if you don't specify a user/password you will be prompted for one
if you don't specify an address it is assumed to be
<app_id>.appspot.com
path: path to remote_api handler, if not
specified, will use /_ah/remote_api
"""
path = path or "/_ah/remote_api"
if not address:
address = "%s.appspot.com" % app_id
init_remote_api(app_id, path, address, user=user, password=password)
def auth_func():
"""
function to prompt user for credentials
"""
email_address = raw_input("Email Address: ")
password = getpass.getpass("Password: ")
return email_address, password
def init_remote_api(app_id, path, address, user=None, password=None):
"""
generic wrapper to initialize the remoteapi for a given path
required
=========
app_id : the app_id of the application to connect to
path: the path to the remote_api handler ex: /_ah/remote_api
address: server to connect to ex: myapp.appspot.com
if user and password are not specified you will be prompted on
connection if needed
"""
if user and password:
def my_auth():
return (user, password)
else:
my_auth = auth_func
remote_api_stub.ConfigureRemoteApi(app_id, path, my_auth, address)
remote_api_stub.MaybeInvokeAuthentication()
os.environ["SERVER_SOFTWARE"] = "Development (remote_api)/1.0"
# example
APP_ID = "s~myapp" # when hrds was introduced it became necessary to specify app_id and address note the "s~..."
ADDRESS = "myapp.appspot.com"
attach_to_app(APP_ID, address=ADDRESS)
这篇关于使用App Engine的Remote_api配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!