我已经为使用Google App Engine的项目开发了一个后端api。 后端(用Java编写)当前具有一个受保护的方法,该方法返回字符串列表。 我遇到的问题是从python客户端访问此后端; 专门访问我编写的后端。 我收到的错误来自以下代码中的凭据设置。
def main():
# Parse command line flags used by the oauth2client library.
parser = argparse.ArgumentParser(
description='Auth sample',
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
flags = parser.parse_args(args=[])
# Acquire and store oauth token.
storage = oauth2client.file.Storage('<PROJECT_NAME>.json')
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = oauth2client.client.OAuth2WebServerFlow(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=SCOPE,
user_agent=USER_AGENT,
xoauth_displayname=OAUTH_DISPLAY_NAME)
credentials = tools.run_flow(flow, storage, flags)
http = httplib2.Http()
http = credentials.authorize(http)
# Build a service object for interacting with the API.
api_root = 'https://localhost:8080/_ah/api'
api = '<BACKEND_API_NAME>'
version = 'v1'
discovery_url = '%s/discovery/v1/apis/%s/%s/rest' % (api_root, api, version)
service = discovery.build(
api, version, discoveryServiceUrl=discovery_url, http=http)
# Fetch all greetings and print them out.
response = service.greetings().list().execute()
return response
这段代码是他们在App Engine网站( https://cloud.google.com/appengine/docs/python/endpoints/access_from_python )上给出的示例,但是,当运行“ tools.run_flow(flow,storage,flags)”时我收到此错误:“ RuntimeError:错误('非法IP地址字符串传递给inet_pton',)”关于此情况的任何建议? 还是有人知道更好的方法来访问受OAuth保护的方法? 谢谢。