在Python中使用Apps Script Execution API时出现404错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在Python中使用Apps Script Execution API时出现404错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1764字,纯文字阅读大概需要3分钟。
内容图文
![在Python中使用Apps Script Execution API时出现404错误](/upload/InfoBanner/zyjiaocheng/767/04cc8eaf9f5c4fcaa5c8f45851737f10.jpg)
尝试使用Apps Script Execution API时,我一直收到404错误.我已确保项目ID已正确链接,并且已启用正确的API.
这是我得到的追溯:
Traceback (most recent call last):
File "", line 70, in main
response = service.scripts().run(body=request, scriptId=SCRIPT_ID).execute()
File "/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "apiclient/http.py", line 723, in execute
raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 404 when requesting https://script.googleapis.com/v1/scripts/ASFDQETWRQWEFAS12341234:run?alt=json returned "Requested entity was not found.">
这是我正在使用的代码:
SCOPES = ['https://mail.google.com/',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets']
SCRIPT_ID = 'ASFDQETWRQWEFAS12341234'
CLIENT_SECRET = '/file/path'
def get_credentials():
with open(CLIENT_SECRET, 'r') as f:
content = json.load(f)
credentials = client.SignedJwtAssertionCredentials(
content['client_email'], content['private_key'].encode(), SCOPES)
if hasattr(credentials, 'access_token'):
if (hasattr(credentials, 'access_token_expired') and
credentials.access_token_expired):
http = httplib2.Http()
credentials.refresh(http)
return credentials
def main(unused_argv):
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = build('script', 'v1', http=http)
request = {
'function': 'test',
'devMode': True
}
response = service.scripts().run(body=request, scriptId=SCRIPT_ID).execute()
if 'error' in response:
raise AppsScriptError(response['error'])
try:
assert str(response['response']['result']) == 'Success!'
except:
raise AppsScriptError('Apps Script didn\'t complete successfully.')
解决方法:
看起来你必须去脚本项目,Publish>部署为API可执行文件并选择谁有权访问该脚本 – 任何人.
内容总结
以上是互联网集市为您收集整理的在Python中使用Apps Script Execution API时出现404错误全部内容,希望文章能够帮你解决在Python中使用Apps Script Execution API时出现404错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。