gpt4 book ai didi

macos - Google Go HelloWorld 教程出错

转载 作者:IT王子 更新时间:2023-10-29 01:00:20 25 4
gpt4 key购买 nike

开始学习 Google Go HelloWorld 教程,来自:

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

在 MacBook Pro 上使用 OS X 10.8.2。

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

这是 Hello World 程序:

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 时 - 不显示问候语 - 屏幕上出现了很多 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'"

最佳答案

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

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

关于macos - Google Go HelloWorld 教程出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com