我需要在创建允许身份验证的服务对象的 http post 请求中插入多个作用域。但是,不幸的是,简单地在字符串中放入多个作用域似乎并不能实现这一目标,而是在底部返回错误。
import gflags
import apiclient
import oauth2client
import argparse
from oauth2client import client
from oauth2client import file
from oauth2client import tools
from apiclient import discovery
from apiclient import sample_tools
import httplib2
import sys
import os
import pprint
from pprint import pprint
name = 'prediction'
scope = "https://www.googleapis.com/auth/prediction https://www.googleapis.com/auth/devstorage.full_control testing_data/training_data.csv testing_data/training_data.csv"
filename = '__file__'
client_secrets = os.path.join(os.path.dirname(filename),
'client_secrets.json')
flow = client.flow_from_clientsecrets(client_secrets,scope=scope)
storage = file.Storage(name+'.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run(flow, storage)
http = credentials.authorize(httplib2.Http())
service = discovery.build('prediction','v1.6',http=http)
papi = service.trainedmodels()
result = papi.list(maxResults=10,project='895092811023').execute()
body = {'id':'Universities','storageDataLocation':'testing_data/training_data.csv'}
start = papi.insert(body=body,project='895092811023').execute()
这是错误,它指出缺少所需的范围。(它正在记录一些范围,因为它将结果保存到结果中,但只是不允许我插入一个新模型,我相信这是因为它没有获得访问此模型数据的范围,这是在 Google Cloud Storage 中?
Traceback (most recent call last):
File "filehere", line 42, in <module>
start = papi.insert(body=body,project='895092811023').execute()
File "buildbdist.win-amd64eggoauth2clientutil.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:Python27libsite-packagesapiclienthttp.py", line 680, in execute
raise HttpError(resp, content, uri=self.uri)
HttpError: <HttpError 401 when requesting https://www.googleapis.com/prediction/v1.6/projects/895092811023/trainedmodels?alt=json returned "Required scope(s) missing.">
你唯一需要传入的作用域是 www.googleapis.com 的东西,例如:https://www.googleapis.com/auth/prediction,不要传入"testing_data/training_data.csv testing_data/training_data.csv"。
您可以随时访问 https://accounts.google.com/b/0/IssuedAuthSubTokens 并查看已授予应用程序的范围。