在本地启动Google App Engine上的Go服务器时出现错误。

huangapple go评论153阅读模式
英文:

Starting Go server on App Engine localhost throws error

问题

有人能告诉我为什么会发生这种情况吗:

$ dev_appserver.py nmg_server
INFO     2017-07-08 17:15:37,369 application_configuration.py:461] 未指定版本。生成的版本 ID 为:20170708t171537
WARNING  2017-07-08 17:15:37,369 application_configuration.py:166] 托管的 VM 运行时已弃用,请考虑将应用迁移到使用灵活运行时。有关更多详细信息,请参阅 https://cloud.google.com/appengine/docs/flexible/python/migrating。
INFO     2017-07-08 17:15:37,472 devappserver2.py:116] 跳过 SDK 更新检查。
INFO     2017-07-08 17:15:37,513 api_server.py:312] 在 http://localhost:54096 启动 API 服务器
INFO     2017-07-08 17:15:37,517 api_server.py:938] 应用所有待处理的事务并保存数据存储
INFO     2017-07-08 17:15:37,517 api_server.py:941] 保存搜索索引
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() 需要准确的 2 个参数(给定了 1 个)

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

英文:

Can anyone tell me why this is happening:

$ 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 &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/dev_appserver.py&quot;, line 103, in &lt;module&gt;
    _run_file(__file__, globals())
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/dev_appserver.py&quot;, line 97, in _run_file
    execfile(_PATHS.script_file(script_name), globals_)
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py&quot;, line 381, in &lt;module&gt;
    main()
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py&quot;, line 369, in main
    dev_server.start(options)
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py&quot;, line 196, in start
    options.api_host, apiserver.port, wsgi_request_info_, options.grpc_apis)
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/dispatcher.py&quot;, line 223, in start
    _module.start()
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py&quot;, line 1647, in start
    self._add_instance()
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/module.py&quot;, line 1799, in _add_instance
    expect_ready_request=True)
  File &quot;/Users/dgaedcke/gcloud_tools/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/go_runtime.py&quot;, line 189, in new_instance
    self._go_application.maybe_build()):
TypeError: maybe_build() takes exactly 2 arguments (1 given)

I'm trying to run my server for testing on localhost and it keeps exiting with this error

答案1

得分: 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文件,如下所示(为方便起见,同时添加了可修补的统一差异以及之前/之后的内容)。

另外考虑迁移到App Engine Flex,因为Managed VMs已被弃用,并且在2017年10月27日之后将不再受支持

> 警告:Managed VMs beta环境(使用vm:true部署的应用程序)已被弃用并将被停用。本页面适用于已在app.yaml中使用vm:true的灵活环境的用户,他们希望升级到最新版本。如果您正在从标准环境更新应用程序,请参阅从标准环境迁移到灵活环境的服务迁移指南

可修补的差异格式

--- /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(&#39;Build succeeded:\n%s\n%s&#39;, stdout, stderr)
 self._go_executable = exe_name

-  def maybe_build(self, maybe_modified_since_last_build):
+  def maybe_build(self):
 &quot;&quot;&quot;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(&#39;appengine-go-bin&#39;)
   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(&#39;Rebuilding Go application due to source modification&#39;)
 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.
&quot;&quot;&quot;
if not self._work_dir:
  self._work_dir = tempfile.mkdtemp(&#39;appengine-go-bin&#39;)
  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(&#39;Rebuilding Go application due to source modification&#39;)
else:
  logging.debug(&#39;Building Go application&#39;)
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.
&quot;&quot;&quot;
if not self._work_dir:
  self._work_dir = tempfile.mkdtemp(&#39;appengine-go-bin&#39;)
  atexit.register(_rmtree, self._work_dir)

if self._go_executable:
  logging.debug(&#39;Rebuilding Go application due to source modification&#39;)
else:
  logging.debug(&#39;Building Go application&#39;)
self._build()
return True
英文:

This appears to be a bug in Cloud SDK which is affecting dev_appserver.py when using with App Engine Managed VMs. It does not seem to be affecting App Engine Standard or App Engine Flex environments.

Until Google releases a new Cloud SDK with the fix, you can modify the CLOUD_SDK_INSTALL_DIR//platform/google_appengine/google/appengine/tools/devappserver2/go_managedvm.py file locally as shown below (added both the patchable unified diff as well as before/after just for convenience).

Also consider moving to App Engine Flex since Managed VMs are deprecated and will not be supported after October 27, 2017.

> Warning: The Managed VMs beta environment (applications deployed with
> vm:true) is deprecated and will be decommissioned. This page is for
> users who are already using the flexible environment with vm:true in
> their app.yaml and want to upgrade to the latest release. If you are
> updating your application from the standard environment, see the
> Migrating Services from the Standard Environment to the Flexible
> Environment instead
.

Diff in patchable format

--- /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(&#39;Build succeeded:\n%s\n%s&#39;, stdout, stderr)
 self._go_executable = exe_name

-  def maybe_build(self, maybe_modified_since_last_build):
+  def maybe_build(self):
 &quot;&quot;&quot;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(&#39;appengine-go-bin&#39;)
   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(&#39;Rebuilding Go application due to source modification&#39;)
 else:

Before:

  def maybe_build(self, maybe_modified_since_last_build):
    &quot;&quot;&quot;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.
    &quot;&quot;&quot;
    if not self._work_dir:
      self._work_dir = tempfile.mkdtemp(&#39;appengine-go-bin&#39;)
      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(&#39;Rebuilding Go application due to source modification&#39;)
    else:
      logging.debug(&#39;Building Go application&#39;)
    self._build()
    return True

After:

  def maybe_build(self):
    &quot;&quot;&quot;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.
    &quot;&quot;&quot;
    if not self._work_dir:
      self._work_dir = tempfile.mkdtemp(&#39;appengine-go-bin&#39;)
      atexit.register(_rmtree, self._work_dir)

    if self._go_executable:
      logging.debug(&#39;Rebuilding Go application due to source modification&#39;)
    else:
      logging.debug(&#39;Building Go application&#39;)
    self._build()
    return True

huangapple
  • 本文由 发表于 2017年7月9日 01:23:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/44988903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定