Python Google Drive服务帐户出现未经授权的客户端异常

Python Google Drive服务帐户出现未经授权的客户端异常,python,google-drive-api,google-oauth,service-accounts,Python,Google Drive Api,Google Oauth,Service Accounts,我正在尝试使用python的服务帐户身份验证来设置一个GoogleDrive应用程序。我已经试过了所有我能找到的说明,但我无法让它授权给客户。以下是我得到的: CLIENT_EMAIL='<stuff>@developer.gserviceaccount.com' f = open('<the .p12 file I downloaded from the OAuth section of the credentials page on the developers conso

我正在尝试使用python的服务帐户身份验证来设置一个GoogleDrive应用程序。我已经试过了所有我能找到的说明,但我无法让它授权给客户。以下是我得到的:

CLIENT_EMAIL='<stuff>@developer.gserviceaccount.com'
f = open('<the .p12 file I downloaded from the OAuth section of the credentials page on the developers console>', 'rb')
key = f.read()
credentials = SignedJwtAssertionCredentials(CLIENT_EMAIL, key, scope='https://www.googleapis.com/auth/drive', sub="<the email address of the account owner listed in the permissions page>")
self.http = credentials.authorize(httplib2.Http())

gauth = GoogleAuth()
gauth.credentials = credentials

self.drive = GoogleDrive(gauth)
我的代码抛出一个
未经授权的客户端异常
。我还尝试将直接下载的JSon中的私钥粘贴到代码中,但这也不起作用。将密钥解码或编码为base64不起作用(给我一些格式错误)。有人知道会出什么问题吗


我也在一个服务器上运行这个程序,这个服务器不是我下载p12文件的地方,但我认为这并不重要。我只是想提一下,以防万一。

在使用google drive sdk时,我也遇到了很多问题。我写了一个小包装,使谷歌驱动Api的使用变得简单(至少对我来说是这样)。您可能会发现它很有用-

您的代码看起来有点不对劲。我认为您没有正确授权您的GoogleDrive服务,谢谢!我将您的代码与我的代码进行了比较,结果发现删除凭据构造函数的“sub=”部分修复了它。
file_list = self.drive.ListFile({'q': "title = '" + id + '.zip' + "'", 'maxResults': 100}).GetList()