服务器端Google API服务请求会产生googleapiclient.errors.HttpError:<HttpError 404

艾略特

我已经创建了服务帐户凭据,并在AWS实例上运行了我的代码。代码是:

from google.oauth2 import service_account
SCOPES = [ 'https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive' ]
SERVICE_ACCOUNT_FILE = 'serviceAccount.json'
APPLICATION_NAME = 'app name'

credentials = service_account.Credentials.from_service_account_file(
          SERVICE_ACCOUNT_FILE, scopes=SCOPES)
    drive_service = discovery.build('drive', 'v2', credentials=credentials)

    settings = configparser.ConfigParser()
    settings._interpolation = configparser.ExtendedInterpolation()
    settings.read('caremarkets.ini')
    origin_file_id = settings.get('GoogleSheetParams',''+manualType+'Manual2018')
    folderId = settings.get('GoogleSheetParams',''+manualType+'FolderID')
    timeStamp = '{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now())
    title = manualType+ " Userid: ( "+str(user_id)+" ) "+timeStamp

    fileObject= drive_service.files().copy(
          fileId=origin_file_id, body={"parents": [{"kind": "drive#fileLink",
                                 "id": folderId}], 'title': title}).execute()

但是,这是我的错误:如上面的代码片段所示,第41行是服务调用:

fileObject= drive_service.files().copy(
      fileId=origin_file_id, body={"parents": [{"kind": "drive#fileLink",
                             "id": folderId}], 'title': title}).execute()


File "/home/ubuntu/dev_deploy/copy_master_spreadsheet_to_user_slave.py", line 41, in copy_master_spreadsheet_to_user_slave
    "id": folderId}], 'title': title}).execute()
File "/usr/local/lib/python3.5/dist-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/googleapiclient/http.py", line 844, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1lNcqvQACH6DOBl3uQywJO1A6Iy6va7YdSrZiobMaOj0/copy?alt=json returned "File not found: 1lNcqvQACH6DOBl3uQywJO1A6Iy6va7YdSrZiobMaOj0">

请注意,以上代码在我的计算机上可以在本地正常运行。在更改代码以使用服务帐户而不是通常的client_secret.json后才得到此

服务帐户密钥信息:

Service account name    Service account ID                                       Key ID                                         Key creation date   Options 
SACxxxxxxs              [email protected]    bf287f0baa29d4fa5f6b98aacf03b8bff13b0447       Mar 15, 2018

非常感谢您的帮助

戴姆敦

找不到文件意味着您提供的文件ID不存在,或者通过身份验证的用户无权访问。

获取服务帐户的电子邮件地址,然后转到网络版Google云端硬盘,与服务帐户共享文件。然后它将有权访问该文件。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用服务帐户时 Google Calendar API HttpError 404

Google Cloud Composer BigQuery运算子-Get Jobs API HTTPError 404

urllib.error.HTTPError: HTTP 错误 404: Not Found using Google Matrix API

Google Sheets API HttpError 500和503

在API请求上获取HTTPError

googleapi v3 api上传错误的googleapiclient.errors.HttpError

HttpError 400错误请求-Google Admin Directory API(Python)

HTTPError 400 | 谷歌云平台将csv导入谷歌sql服务器(云sql)

urllib.error.HTTPError:HTTP 错误 404:找不到可以在浏览器中打开的链接

使用urllib2时,获取HTTPError 404

Python:urllib.error.HTTPError:HTTP错误404:找不到

Python urllib.error.HTTPError:HTTP 错误 404:未找到

urllib.error.HTTPError:HTTP 错误 404:未找到

在 python 中为 gcloud 命令捕获“HTTPError 404”

HTTPError:HTTP错误503:服务不可用的goslate语言检测请求:Python

urllib.error.HTTPError:HTTP错误503:服务不可用python

HTTPError:服务暂时不可用(多线程下载Wikipedia数据转储)

urllib2.HTTPError:HTTP错误400:错误的请求-django ping_google

Google API和Directory SDK:获取每个域的组数:HttpError(“ group”)

处理HTTPError时出错

如何引发HTTPError

从Mechanize中的HTTPError恢复

ServiceStack和HttpError

requests.exceptions.HTTPError:400客户端错误:错误的网址请求:https://accounts.spotify.com/api/token

HttpError 400前提条件检查在users()。messages()。list使用服务帐户调用Gmail API期间失败

HTTPError问题:urllib.request.urlopen python请求错误

再次urllib.error.HTTPError:HTTP错误400:错误的请求

urllib2.HTTPError:HTTP错误400:错误的请求-Python

服务器端Google授权