Google App脚本-“消息":“未找到请求的实体".与devMode = false [英] Google App Script - "message": "Requested entity was not found." with devMode = false

查看:54
本文介绍了Google App脚本-“消息":“未找到请求的实体".与devMode = false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Python脚本与Google App Script中的项目连接.我已经遵循了

部署完成后,转到python脚本,并使用部署ID修改 SCRIPT ID

I am trying to connect my Python script with my project in Google App Script. I have followed all the insctructions in this guide.

I have of course deployed it as an executable API and have tested it with access to only myself, my organization and anyone options.

When I pass the request with devMode as true, it all works fine. I understand that in this case, it is running the latest saved version. However when I set it to false then I get back the error "message": "Requested entity was not found." which as I understand is trying to run the latest deployed version.

I have also tried going through these questions 1 and 2 but apparently, the problem they had was the opposite where the script wouldn't run with devMode set to true.

Everything else seems to be executing correctly but I cannot find the reason why it wouldn't run the script without being on devMode

This is my script:

"""
Shows basic usage of the Apps Script API.
Call the Apps Script API to create a new script project, upload a file to the
project, and log the script's URL to the user.
"""
from __future__ import print_function
import pickle
import os.path
from googleapiclient import errors
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/script.projects',
          'https://www.googleapis.com/auth/spreadsheets.currentonly'
          ]

SCRIPT_ID = 'someid'


def main():
    """Calls the Apps Script API.
    """
    creds = None
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('script', 'v1', credentials=creds)

    # Call the Apps Script API
    try:
        # Create a new project
        request = {'function': 'setData'}
        response = service.scripts().run(body=request,
                                         scriptId=SCRIPT_ID).execute()

        print(response)
    except errors.HttpError as error:
        # The API encountered a problem.
        print(error.content)


if __name__ == '__main__':
    main()

解决方案

I have been able to face the same issue and I have found out that changing the script Id to the Deployment Id worked.

The deployment Id can be found on the Apps Script script:

  • Open the script
  • Go to Deploy -> Manage Deployments
  • Get the Deployment ID from the active deployment

Once you have the deployment, go to the python script and modify the SCRIPT ID with the Deployment Id

这篇关于Google App脚本-“消息":“未找到请求的实体".与devMode = false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆