首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >谷歌Go HelloWorld教程出错

谷歌Go HelloWorld教程出错
EN

Stack Overflow用户
提问于 2012-10-15 02:32:08
回答 2查看 1K关注 0票数 3

从以下网址开始学习Google Go HelloWorld教程:

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

在MacBook专业版上使用OS X 10.8.2。

执行了这些步骤,但是当我运行第一个代码( dev_appserver.py myapp/ )时,我得到了问题末尾列出的错误。

这是hello world程序:

代码语言:javascript
复制
package hello

import (
    "fmt"
    "net/http"
)

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

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

这是配置文件:

代码语言:javascript
复制
application: helloworld
version: 1
runtime: go
api_version: go1

处理程序:

代码语言:javascript
复制
- url: /.*
  script: _go_app

我已经在stackoverflow上搜索过了,但没有找到解决方案。

如果你有任何想法/建议,请告诉我。

代码语言:javascript
复制
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)确实有帮助。仍给出错误信息,但服务器启动。

它现在说:

代码语言:javascript
复制
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脚本异常的屏幕。

在最下面是这样写的:

代码语言:javascript
复制
<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错误的全文如下:

代码语言:javascript
复制
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'"
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-15 11:54:19

扩展Kyle的答案,这是我为了让它工作所做的:

票数 3
EN

Stack Overflow用户

发布于 2012-10-15 11:21:12

Go使用与您已安装的python版本不同的SDK。请在此处下载:

Google App Engine SDK for Go

在启动服务器时,一定要执行它的dev_appserver.py脚本。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12885235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档