Google App Engine Go SDK:对’/’的请求失败

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

Google App Engine Go SDK: Request to '/' failed

问题

我刚刚开始使用GAE,我在这里有以下指南:https://developers.google.com/appengine/docs/go/gettingstarted/devenvironment,并且这里有一些hello world教程:https://developers.google.com/appengine/docs/go/gettingstarted/helloworld。

我的问题是,当我输入goapp serve时,它可以工作,并显示如下日志:

INFO     2014-05-18 08:44:57,130 devappserver2.py:765] Skipping SDK update check.
WARNING  2014-05-18 08:44:57,135 api_server.py:374] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2014-05-18 08:44:57,140 api_server.py:171] Starting API server at: http://localhost:59559
INFO     2014-05-18 08:44:57,154 dispatcher.py:182] Starting module "default" running at: http://localhost:8080
INFO     2014-05-18 08:44:57,156 admin_server.py:117] Starting admin server at: http://localhost:8000

但是,当我尝试访问http://localhost:8080时,在浏览器中没有显示"hello, world!",并且错误日志显示如下:

ERROR    2014-05-18 08:48:05,002 module.py:714] Request to '/' failed
Traceback (most recent call last):
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/module.py", line 708, in _handle_request
environ, wrapped_start_response)
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/module.py", line 1228, in _handle_script_request
request_type)
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/instance.py", line 382, in handle
request_type))
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/http_proxy.py", line 148, in handle
connection.connect()
File "/home/bayu/.pyenv/versions/2.7.6/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/home/bayu/.pyenv/versions/2.7.6/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 111] Connection refused
INFO     2014-05-18 08:48:05,007 module.py:639] default: "GET / HTTP/1.1" 500 -

我已经搜索了一下,并尝试了这里的另一个入门教程:http://blog.joshsoftware.com/2014/03/12/learn-to-build-and-deploy-simple-go-web-apps-part-one/,但也没有成功。

我该怎么办?

  • 我使用的是Ubuntu 12.04,Python 2.7.3,go版本go1.2.1 linux/386
  • 使用的是go_appengine_sdk_linux_386-1.9.4.zip

这是我的hello.go和app.yaml文件:

hello.go

package hello

import (
   "fmt"
   "net/http"
)

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

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

app.yaml

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

handlers:
- url: /.*
  script: _go_app

谢谢。

英文:

i'm just getting started using GAE, i have following guide in here https://developers.google.com/appengine/docs/go/gettingstarted/devenvironment and some hello word tutorial here https://developers.google.com/appengine/docs/go/gettingstarted/helloworld .

my problem is when i'm typing goapp serve it works. and show log like this:

INFO     2014-05-18 08:44:57,130 devappserver2.py:765] Skipping SDK update check.
WARNING  2014-05-18 08:44:57,135 api_server.py:374] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2014-05-18 08:44:57,140 api_server.py:171] Starting API server at: http://localhost:59559
INFO     2014-05-18 08:44:57,154 dispatcher.py:182] Starting module "default" running at: http://localhost:8080
INFO     2014-05-18 08:44:57,156 admin_server.py:117] Starting admin server at: http://localhost:8000

but, when i'm trying to access http://localhost:8080 , it not show me "hello, world!" in the browser. and error log show me like this:

ERROR    2014-05-18 08:48:05,002 module.py:714] Request to '/' failed
Traceback (most recent call last):
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/module.py", line 708, in _handle_request
environ, wrapped_start_response)
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/request_rewriter.py", line 311, in _rewriter_middleware
response_body = iter(application(environ, wrapped_start_response))
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/module.py", line 1228, in _handle_script_request
request_type)
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/instance.py", line 382, in handle
request_type))
File "/home/bayu/.go_appengine/google/appengine/tools/devappserver2/http_proxy.py", line 148, in handle
connection.connect()
File "/home/bayu/.pyenv/versions/2.7.6/lib/python2.7/httplib.py", line 772, in connect
self.timeout, self.source_address)
File "/home/bayu/.pyenv/versions/2.7.6/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 111] Connection refused
INFO     2014-05-18 08:48:05,007 module.py:639] default: "GET / HTTP/1.1" 500 -

i have google it and trying another get started tutorial in here http://blog.joshsoftware.com/2014/03/12/learn-to-build-and-deploy-simple-go-web-apps-part-one/
but it's not work also.

what should i do?

  • i'm on ubuntu 12.04 , Python 2.7.3, go version go1.2.1 linux/386
  • using go_appengine_sdk_linux_386-1.9.4.zip

this is my hello.go and app.yaml

hello.go

package hello

import (
   "fmt"
   "net/http"
)

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

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

app.yaml

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

handlers:
- url: /.*
  script: _go_app

thank you,

答案1

得分: 1

不确定这是否对任何人有帮助,但我遇到了完全相同的问题,最终追踪到是我的hosts文件引起的。基本上,应用引擎服务器正在运行在0.0.0.0:8080,但界面/输出显示的是localhost:8080。在我的hosts文件中,0.0.0.0:8080没有映射到localhost,所以:

  1. 使用vim或其他编辑器编辑你的/private/etc/hosts文件
  2. 在hosts文件中添加0.0.0.0 localhost
  3. 保存文件,打开一个新的终端,尝试重新运行你的应用引擎服务器

在进行了这个简单的编辑之后,一切都正常工作了。

英文:

Not sure if this will help anyone or not but I came across the exact same issues and finally tracked it down to my hosts file. Basically what is happening is the app engine server is running on 0.0.0.0:8080 yet the interface / output is displaying localhost:8080. In my hosts file 0.0.0.0:8080 wasn't mapped to localhost so:

  1. edit your /private/etc/hosts file with vim or whatever
  2. add 0.0.0.0 localhost to your hosts file
  3. save, start a new terminal and try and run you appengine server again

After that simple edit everything worked for me.

huangapple
  • 本文由 发表于 2014年5月19日 16:55:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/23733570.html
匿名

发表评论

匿名网友

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

确定