【问题标题】:appcfg.py not working in command lineappcfg.py 在命令行中不起作用
【发布时间】:2016-01-12 21:18:07
【问题描述】:

我只是有点难以理解为什么这个命令:

>appcfg.py -A adept-box-109804 update app.yaml

“立即试用 Google App Engine”页面无法正常工作。我已经下载了适用于 Python 的 App Engine SDK,并将路径设置为指向 appcfg.py 的位置,但是在我的项目根目录中运行 appcfg.py 在命令行中不起作用。我要么必须导航到包含 appcfg.py 的文件夹并执行

>python appcfg.py help

或者做

>python "C:\Program Files (x86)\Google\google_appengine\appcfg.py" help

让命令在任何地方工作。我使用后一种方法来部署我的测试应用程序,但只是想知道是否有人可以解释为什么简单的谷歌教程给出的命令没有做任何事情。我还检查以确保使用 Python 2.7 解释器自动打开 .py 文件,这样只需键入即可在命令行中执行文件 hello.py

>hello.py

它会输出它的打印语句。另一方面,无论参数如何,以类似方式使用 appcfg.py 都会给出相同的输出(请注意,我截断了输出,但请放心,无论参数如何,它们都是相同的:

C:\>appcfg.py help backends
Usage: appcfg.py [options] <action>

Action must be one of:
  backends: Perform a backend action.
  backends configure: Reconfigure a backend without stopping it.
  backends delete: Delete a backend.
  backends list: List all backends configured for the app.
  backends rollback: Roll back an update of a backend.
  backends start: Start a backend.
  backends stop: Stop a backend.
  backends update: Update one or more backends.
  create_bulkloader_config: Create a bulkloader.yaml from a running application.
  cron_info: Display information about cron jobs.
  delete_version: Delete the specified version for an app.
  download_app: Download a previously-uploaded app.
  download_data: Download entities from datastore.
  help: Print help for a specific action.
  list_versions: List all uploaded versions for an app.
  request_logs: Write request logs in Apache common log format.
  resource_limits_info: Get the resource limits.
  rollback: Rollback an in-progress update.
  set_default_version: Set the default (serving) version.
  start_module_version: Start a module version.
  stop_module_version: Stop a module version.
  update: Create or update an app version.
  update_cron: Update application cron definitions.
  update_dispatch: Update application dispatch definitions.
  update_dos: Update application dos definitions.
  update_indexes: Update application indexes.
  update_queues: Update application task queue definitions.
  upload_data: Upload data records to datastore.
  vacuum_indexes: Delete unused indexes from application.
Use 'help <action>' for a detailed description.

C:\>appcfg.py help update
Usage: appcfg.py [options] <action>

Action must be one of:
  backends: Perform a backend action.
  backends configure: Reconfigure a backend without stopping it.
  backends delete: Delete a backend.
  backends list: List all backends configured for the app.
  backends rollback: Roll back an update of a backend.
  backends start: Start a backend.
  backends stop: Stop a backend.
  backends update: Update one or more backends.
  create_bulkloader_config: Create a bulkloader.yaml from a running application.
  cron_info: Display information about cron jobs.
  delete_version: Delete the specified version for an app.
  download_app: Download a previously-uploaded app.
  download_data: Download entities from datastore.
  help: Print help for a specific action.
  list_versions: List all uploaded versions for an app.
  request_logs: Write request logs in Apache common log format.
  resource_limits_info: Get the resource limits.
  rollback: Rollback an in-progress update.
  set_default_version: Set the default (serving) version.
  start_module_version: Start a module version.
  stop_module_version: Stop a module version.
  update: Create or update an app version.
  update_cron: Update application cron definitions.
  update_dispatch: Update application dispatch definitions.
  update_dos: Update application dos definitions.
  update_indexes: Update application indexes.
  update_queues: Update application task queue definitions.
  upload_data: Upload data records to datastore.
  vacuum_indexes: Delete unused indexes from application.
Use 'help <action>' for a detailed description.

【问题讨论】:

    标签: python-2.7 google-app-engine appcfg


    【解决方案1】:

    我终于找到了真正的原因,这不是 AppEngine SDK 的错误。而是我的 Python 解释器,因为我注意到它不接受任何 .py 文件的参数。结果是一个注册表错​​误,位于 [HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command],我不得不将值从 "C:\Python27\python.exe" "%1" 更改为 "C:\Python27\python.exe" "%1" %*

    这是如何发生的,无论是 Python 2.7 安装程序,还是 AppEngine SDK,我都不确定。

    【讨论】:

      【解决方案2】:

      您的困惑可能源于混淆了 2 种可能的调用样式:

      1. python appcfg.py ...
      2. appcfg.py ...

      第一个不能利用appcfg.py的位置在路径中的事实,它只是python可执行文件的一个参数,它无法找到appcfg.py文件,除非:

      • 在当前目录中找到它
      • appcfg.py 文件是使用完整路径或相对于调用 python 的当前工作目录的相对路径指定的

      这就是您的第二个和第三个命令无法按预期工作的原因。如果appcfg.py 的位置在路径中,则使用第二种调用样式应该可以工作 - 就像您最后一次调用命令一样。

      要记住的关键点:路径配置仅适用于命令可执行文件,而不适用于其参数(顺便说一句,每个可执行文件都可以按照自己的意愿处理,一些可执行文件可能将参数与路径配置相结合以获得文件的位置)。

      同样,appcfg.py 本身(一旦使用两种调用样式中的任何一种成功调用)也需要能够找到指定为参数的app.yaml 文件。它不能这样做,除非:

      • 在当前目录中找到它
      • app.yaml 文件(或其目录)使用完整路径或相对于调用 appcfg.py 的当前工作目录的相对路径指定

      我怀疑appcfg.py 无法找到您的app.yaml 文件可能是您提到的第一个命令不起作用的原因。如果不是,您应该提供有关失败的详细信息。

      关于为什么不管参数如何,最后一个命令的输出都是相同的,我不确定,这可能是 SDK 的 windows 版本中的错误。在linux中输出不同:

      > appcfg.py help backends
      Usage: appcfg.py [options] backends <directory> <action>
      
      Perform a backend action.
      
      The 'backends' command will perform a backends action.
      
      Options:
        -h, --help            Show the help message and exit.
        -q, --quiet           Print errors only.
        -v, --verbose         Print info level logs.
        --noisy               Print all logs.
        -s SERVER, --server=SERVER
                              The App Engine server.
        -e EMAIL, --email=EMAIL
                              The username to use. Will prompt if omitted.
        -H HOST, --host=HOST  Overrides the Host header sent with all RPCs.
        --no_cookies          Do not save authentication cookies to local disk.
        --skip_sdk_update_check
                              Do not check for SDK updates.
        -A APP_ID, --application=APP_ID
                              Set the application, overriding the application value
                              from app.yaml file.
        -M MODULE, --module=MODULE
                              Set the module, overriding the module value from
                              app.yaml.
        -V VERSION, --version=VERSION
                              Set the (major) version, overriding the version value
                              from app.yaml file.
        -r RUNTIME, --runtime=RUNTIME
                              Override runtime from app.yaml file.
        -E NAME:VALUE, --env_variable=NAME:VALUE
                              Set an environment variable, potentially overriding an
                              env_variable value from app.yaml file (flag may be
                              repeated to set multiple variables).
        -R, --allow_any_runtime
                              Do not validate the runtime in app.yaml
        --oauth2              Ignored (OAuth2 is the default).
        --oauth2_refresh_token=OAUTH2_REFRESH_TOKEN
                              An existing OAuth2 refresh token to use. Will not
                              attempt interactive OAuth approval.
        --oauth2_access_token=OAUTH2_ACCESS_TOKEN
                              An existing OAuth2 access token to use. Will not
                              attempt interactive OAuth approval.
        --authenticate_service_account
                              Authenticate using the default service account for the
                              Google Compute Engine VM in which appcfg is being
                              called
        --noauth_local_webserver
                              Do not run a local web server to handle redirects
                              during OAuth authorization.
      

      【讨论】:

      • 感谢丹的简洁明了的回答。我还怀疑在使用 appcfg.py 调用时,相同的输出是 Windows 版本的错误。值得庆幸的是,使用 python appcfg.py 调用仍然可以访问 appcfg 的全部功能。
      • 这可以解释为什么这个错误会被忽视到已发布的 SDK 版本中:)
      【解决方案3】:

      我遇到了这个问题,并且在局部变量python版本中加深了与应用引擎python版本不同的地方。 所以解决方法就是在脚本前加上当前python版本的位置:

      C:\Python27\python.exe "C:\Program Files (x86)\Google\google_appengine\appcfg.py"
      

      它只是恢复正常工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-31
        • 1970-01-01
        • 1970-01-01
        • 2013-01-24
        • 1970-01-01
        • 2018-01-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多