【问题标题】:Starting Go server on App Engine localhost throws error在 App Engine localhost 上启动 Go 服务器会引发错误
【发布时间】:2017-07-08 17:23:38
【问题描述】:

谁能告诉我为什么会这样:

$ dev_appserver.py nmg_server
INFO     2017-07-08 17:15:37,369 application_configuration.py:461] No version specified. Generated version id: 20170708t171537
WARNING  2017-07-08 17:15:37,369 application_configuration.py:166] The Managed VMs runtime is deprecated, please consider migrating your application to use the Flexible runtime. See https://cloud.google.com/appengine/docs/flexible/python/migrating for more details.
INFO     2017-07-08 17:15:37,472 devappserver2.py:116] Skipping SDK update check.
INFO     2017-07-08 17:15:37,513 api_server.py:312] Starting API server at: http://localhost:54096
INFO     2017-07-08 17:15:37,517 api_server.py:938] Applying all pending transactions and saving the datastore
INFO     2017-07-08 17:15:37,517 api_server.py:941] Saving search indexes
Traceback (most recent call last):
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 103, in <module>
    _run_file(__file__, globals())
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 97, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 381, in <module>
    main()
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 369, in main
    dev_server.start(options)
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 196, in start
    options.api_host, apiserver.port, wsgi_request_info_, options.grpc_apis)
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py", line 223, in start
    _module.start()
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1647, in start
    self._add_instance()
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py", line 1799, in _add_instance
    expect_ready_request=True)
  File "/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/go_runtime.py", line 189, in new_instance
    self._go_application.maybe_build()):
TypeError: maybe_build() takes exactly 2 arguments (1 given)

我正在尝试在本地主机上运行我的服务器进行测试,但它一直退出并出现此错误

【问题讨论】:

    标签: google-app-engine go


    【解决方案1】:

    这似乎是 Cloud SDK 中的一个错误,它在与 App Engine Managed VMs 一起使用时会影响 dev_appserver.py。它似乎不会影响 App Engine Standard 或 App Engine Flex 环境。

    在 Google 发布带有此修复程序的新 Cloud SDK 之前,您可以在本地修改 CLOUD_SDK_INSTALL_DIR//platform/google_appengine/google/appengine/tools/devappserver2/go_managedvm.py 文件,如下所示(添加可修补的统一差异以及之前/之后只是为了方便)。

    还考虑从Managed VMs are deprecated and will not be supported after October 27, 2017 开始迁移到 App Engine Flex。

    警告:托管 VM 测试环境(使用 vm:true) 已弃用并将停用。此页面适用于 已经在使用vm:true 的柔​​性环境的用户 他们的app.yaml 并希望升级到最新版本。如果你是 从标准环境更新您的应用程序,请参阅 Migrating Services from the Standard Environment to the Flexible Environment instead.

    可修补格式的差异

    --- /Users/tuxdude/google-cloud-sdk-orig/platform/google_appengine/google/appengine/tools/devappserver2go_managedvm.py     2017-07-08 11:11:11.000000000 -0700
    +++ /Users/tuxdude/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/go_managedvm.py      2017-07-08 11:11:11.000000000 -0700
    @@ -152,15 +152,9 @@
         logging.debug('Build succeeded:\n%s\n%s', stdout, stderr)
         self._go_executable = exe_name
    
    -  def maybe_build(self, maybe_modified_since_last_build):
    +  def maybe_build(self):
         """Builds an executable for the application if necessary.
    
    -    Args:
    -      maybe_modified_since_last_build: True if any files in the application root
    -          or the GOPATH have changed since the last call to maybe_build, False
    -          otherwise. This argument is used to decide whether a build is Required
    -          or not.
    -
         Returns:
           True if compilation was successfully performed (will raise
             an exception if compilation was attempted but failed).
    @@ -173,9 +167,6 @@
           self._work_dir = tempfile.mkdtemp('appengine-go-bin')
           atexit.register(_rmtree, self._work_dir)
    
    -    if self._go_executable and not maybe_modified_since_last_build:
    -      return False
    -
         if self._go_executable:
           logging.debug('Rebuilding Go application due to source modification')
         else:
    

    之前:

      def maybe_build(self, maybe_modified_since_last_build):
        """Builds an executable for the application if necessary.
    
        Args:
          maybe_modified_since_last_build: True if any files in the application root
              or the GOPATH have changed since the last call to maybe_build, False
              otherwise. This argument is used to decide whether a build is Required
              or not.
    
        Returns:
          True if compilation was successfully performed (will raise
            an exception if compilation was attempted but failed).
          False if compilation was not attempted.
    
        Raises:
          BuildError: if building the executable fails for any reason.
        """
        if not self._work_dir:
          self._work_dir = tempfile.mkdtemp('appengine-go-bin')
          atexit.register(_rmtree, self._work_dir)
    
        if self._go_executable and not maybe_modified_since_last_build:
          return False
    
        if self._go_executable:
          logging.debug('Rebuilding Go application due to source modification')
        else:
          logging.debug('Building Go application')
        self._build()
        return True
    

    之后:

      def maybe_build(self):
        """Builds an executable for the application if necessary.
    
        Returns:
          True if compilation was successfully performed (will raise
            an exception if compilation was attempted but failed).
          False if compilation was not attempted.
    
        Raises:
          BuildError: if building the executable fails for any reason.
        """
        if not self._work_dir:
          self._work_dir = tempfile.mkdtemp('appengine-go-bin')
          atexit.register(_rmtree, self._work_dir)
    
        if self._go_executable:
          logging.debug('Rebuilding Go application due to source modification')
        else:
          logging.debug('Building Go application')
        self._build()
        return True
    

    【讨论】:

    • 我什至不打算使用托管虚拟机,而且我没有任何东西(我可以在我的 app.yaml 文件中看到这会让 GAE 认为......我会喜欢使用 Flex 或 Std(无论哪个支持端点)
    • runtime: go api_version: go1 service: default env: flex threadsafe: yes instance_class: F1 automatic_scaling: beta_settings: # 启用 Google Cloud Endpoints API 管理。 use_endpoints_api_management: true # 指定 Swagger API 规范。 endpoints_swagger_spec_file: swagger/swagger.yaml
    • 这就是我上面的 app.yaml .....我不知道如何让它换行,但我没有看到任何关于 vm 的内容,也许一些 beta 命令是令人困惑的 appengine 我想使用任务队列,所以看来我需要使用 GAE 标准(而不是 flex)会禁止我使用端点吗?
    • @Dewey - 我不太熟悉 Cloud Endpoints 与 App Engine 的集成。在快速搜索中,我找到了this tutorial,其中提到了使用 App Engine 标准支持 Java 8 和 Python 运行时。理论上,我看不出 Go 运行时不受支持的直接原因,因为端点只是普通的 HTTP,但可能存在一些限制。您可以试一试吗 - 将 GAE 标准与 Cloud Endpoints 结合使用(使用教程作为参考)?
    • 是的...这是一个很好的教程,我已经看过了,但是直到我弄清楚为什么 appengine 认为我正在尝试使用托管 VM 并解决部署问题之前,我不是清楚该教程将如何帮助我。您是否在我的 app.yaml 中看到任何暗示 VM & 应该导致此“maybe_build() 恰好需要 2 个参数(1 个给定)”崩溃的内容?换句话说,我如何回到 Standard 或 Flex,这样我就不必修补 Google 的代码或部署到错误的 GAE 基础架构?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 2014-05-27
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 2020-02-20
    • 2013-04-18
    相关资源
    最近更新 更多