Google Go Hello World Tutorial犯了错误

时间:2012-10-14 18:32:08

标签: macos google-app-engine go

开始使用Google Go HelloWorld教程:

https://developers.google.com/appengine/docs/go/gettingstarted/helloworld

在MacBook Pro上使用OS X 10.8.2。

按照步骤操作,但是当我运行第一个代码(dev_appserver.py myapp /)时,我会在问题结尾处列出错误。

这是你好世界的节目:

package hello

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, world!")
}

这是配置文件:

application: helloworld
version: 1
runtime: go
api_version: go1

处理程序:

- url: /.*
  script: _go_app

在stackoverflow上搜索并搜索了这里,但找不到解决方案。

如果您有任何想法/建议,请与我们联系。

Last login: Sun Oct 14 13:05:37 on ttys000
derek-etnyres-macbook-pro-2:~ dereketnyre$ dev_appserver.py myapp/
WARNING  2012-10-14 18:19:54,239 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
Warning: You are using a Python runtime (2.7) that is more recent than the production runtime environment (2.5). Your application may use features that are not available in the production environment and may not work correctly when deployed to production.
CRITICAL 2012-10-14 18:19:54,686 appcfg.py:562] The api_version specified in app.yaml (go1) is not supported by this release of the SDK.  The supported api_versions are ['1'].

==========

更新

将api_version更改为1(api_version:1)并确实有所帮助。仍然提供错误消息,但服务器启动。

现在说:

derek-etnyres-macbook-pro-2:~ dereketnyre$ dev_appserver.py myapp/
WARNING  2012-10-14 21:03:14,910 rdbms_mysqldb.py:74] The rdbms API is not available because the MySQLdb library could not be loaded.
Warning: You are using a Python runtime (2.7) that is more recent than the production runtime environment (2.5). Your application may use features that are not available in the production environment and may not work correctly when deployed to production.
INFO     2012-10-14 21:03:15,324 appcfg.py:585] Checking for updates to the SDK.
INFO     2012-10-14 21:03:15,551 appcfg.py:603] The SDK is up to date.
WARNING  2012-10-14 21:03:15,551 datastore_file_stub.py:518] Could not read datastore data from /var/folders/s0/095xdtkd3cgbjp73tpxx309r0000gn/T/dev_appserver.datastore
WARNING  2012-10-14 21:03:15,552 simple_search_stub.py:949] Could not read search indexes from /var/folders/s0/095xdtkd3cgbjp73tpxx309r0000gn/T/dev_appserver.searchindexes
WARNING  2012-10-14 21:03:15,562 dev_appserver.py:3621] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO     2012-10-14 21:03:15,570 dev_appserver_multiprocess.py:655] Running application dev~helloworld on port 8080: http://localhost:8080
INFO     2012-10-14 21:03:15,570 dev_appserver_multiprocess.py:657] Admin console is available at: http://localhost:8080/_ah/admin

当我使用Safari转到localhost:8080时 - 不显示hello word - 给出一个充满python脚本异常的屏幕。

最底层说:

<type 'exceptions.Exception'>: no goroot found at /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/goroot 
      args = ('no goroot found at /Applications/GoogleAppEngine...bundle/Contents/Resources/google_appengine/goroot',) 
      message = 'no goroot found at /Applications/GoogleAppEngine...bundle/Contents/Resources/google_appengine/goroot'

看起来路径设置不正确吗?

python错误的全文是:

pe 'exceptions.AttributeError'> Python 2.7.2: /usr/bin/python
Sun Oct 14 21:29:05 2012
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.

 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py in _HandleRequest(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>)
   2952         outfile = cStringIO.StringIO()
   2953         try:
=> 2954           self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
   2955         finally:
   2956           self.module_manager.UpdateModuleFileModificationTimes()
self = <google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>, self._Dispatch = <bound method DevAppServerRequestHandler._Dispat...v_appserver.DevAppServerRequestHandler instance>>, dispatcher = <google.appengine.tools.dev_appserver.MatcherDispatcher object>, self.rfile = <socket._fileobject object>, outfile = <cStringIO.StringO object>, env_dict = {'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...}
 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py in _Dispatch(self=<google.appengine.tools.dev_appserver.DevAppServerRequestHandler instance>, dispatcher=<google.appengine.tools.dev_appserver.MatcherDispatcher object>, socket_infile=<socket._fileobject object>, outfile=<cStringIO.StringO object>, env_dict={'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...})
   2822           dispatcher.Dispatch(app_server_request,
   2823                               outfile,
=> 2824                               base_env_dict=env_dict)
   2825         finally:
   2826           request_file.close()
base_env_dict undefined, env_dict = {'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...}
 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.MatcherDispatcher object>, request=<AppServerRequest relative_url: / path: _go_app ...p', mode 'rb' at 0x106afb030> force_admin: False>, outfile=<cStringIO.StringO object>, base_env_dict={'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...})
    705         forward_request = dispatcher.Dispatch(request,
    706                                               outfile,
=>  707                                               base_env_dict=base_env_dict)
    708 
    709         while forward_request:
base_env_dict = {'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...}
 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py in Dispatch(self=<google.appengine.tools.dev_appserver.CGIDispatcher object>, request=<AppServerRequest relative_url: / path: _go_app ...p', mode 'rb' at 0x106afb030> force_admin: False>, outfile=<cStringIO.StringO object>, base_env_dict={'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_ID_HASH': 'C1DFD96E', 'REQUEST_METHOD': 'GET', 'SDK_VERSION': '1.7.2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', ...})
   1770                      memory_file,
   1771                      outfile,
=> 1772                      self._module_dict)
   1773     finally:
   1774       logging.root.level = before_level
self = <google.appengine.tools.dev_appserver.CGIDispatcher object>, self._module_dict = {'codecs': <module 'codecs' from '/System/Library/Framework...framework/Versions/2.7/lib/python2.7/codecs.pyc'>, 'email': <module 'email' from '/System/Library/Frameworks...k/Versions/2.7/lib/python2.7/email/__init__.pyc'>, 'email.Charset': <email.LazyImporter object>, 'email.Encoders': <email.LazyImporter object>, 'email.Errors': <email.LazyImporter object>, 'email.FeedParser': <email.LazyImporter object>, 'email.Generator': <email.LazyImporter object>, 'email.Header': <email.LazyImporter object>, 'email.Iterators': <email.LazyImporter object>, 'email.MIMEAudio': <email.LazyImporter object>, ...}
 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver.py in ExecuteCGI(config=<AppInfoExternal version=1 source_lang...e=None runtime=go api_config=None >, root_path='/Users/dereketnyre/myapp', handler_path='_go_app', cgi_path='/Users/dereketnyre/myapp/_go_app', env={'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE': 'en-us', ...}, infile=<cStringIO.StringO object>, outfile=<cStringIO.StringO object>, module_dict={'codecs': <module 'codecs' from '/System/Library/Framework...framework/Versions/2.7/lib/python2.7/codecs.pyc'>, 'email': <module 'email' from '/System/Library/Frameworks...k/Versions/2.7/lib/python2.7/email/__init__.pyc'>, 'email.Charset': <email.LazyImporter object>, 'email.Encoders': <email.LazyImporter object>, 'email.Errors': <email.LazyImporter object>, 'email.FeedParser': <email.LazyImporter object>, 'email.Generator': <email.LazyImporter object>, 'email.Header': <email.LazyImporter object>, 'email.Iterators': <email.LazyImporter object>, 'email.MIMEAudio': <email.LazyImporter object>, ...}, exec_script=<function ExecuteOrImportScript>, exec_py27_handler=<function ExecutePy27Handler>)
   1588     from google.appengine.ext.go import execute_go_cgi
   1589     return execute_go_cgi(root_path, config, handler_path, cgi_path,
=> 1590         env, infile, outfile)
   1591 
   1592 
env = {'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE': 'en-us', ...}, infile = <cStringIO.StringO object>, outfile = <cStringIO.StringO object>
 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/go/__init__.py in execute_go_cgi(root_path='/Users/dereketnyre/myapp', config=<AppInfoExternal version=1 source_lang...e=None runtime=go api_config=None >, handler_path='_go_app', cgi_path='/Users/dereketnyre/myapp/_go_app', env={'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE': 'en-us', ...}, infile=<cStringIO.StringO object>, outfile=<cStringIO.StringO object>)
    519     RAPI_HANDLER = handler.ApiCallHandler()
    520     GO_APP = GoApp(root_path)
=>  521   GO_APP.make_and_run(env)
    522 
    523 
global GO_APP = None, GO_APP.make_and_run undefined, env = {'APPENGINE_RUNTIME': 'go', 'APPLICATION_ID': 'dev~helloworld', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'DEFAULT_VERSION_HOSTNAME': 'localhost:8080', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE': 'en-us', ...}
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'make_and_run' 
      args = ("'NoneType' object has no attribute 'make_and_run'",) 
      message = "'NoneType' object has no attribute 'make_and_run'"

2 个答案:

答案 0 :(得分:3)

从凯尔那里扩展答案,这就是我为使其发挥作用而做的事情:

  1. 下载SDK
  2. 将其解压缩至/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine
  3. 关闭(如果打开)GAE Launcher并重新运行
  4. 启动您的应用并在浏览器中将其打开

答案 1 :(得分:2)

Go使用您安装的python版本的单独SDK。请在这里下载:

Google App Engine SDK for Go

启动服务器时,请务必执行dev_appserver.py脚本。

相关问题