权限被拒绝错误在从AppEngine Go调用外部服务时发生。

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

Permission Denied error calling external service from appengine go

问题

当我在我的Go代码中调用另一个web服务时,我遇到了权限被拒绝的错误。

以下是我服务器端Go程序中处理程序代码的一部分:

client := http.Client{}
if resp, err := client.Get("http://api.wipmania.com/" + r.RemoteAddr); err != nil {
    c.Errorf("Error getting location from ip: %s", err.Error())
}

从日志中看到:

Error getting location from ip: Get http://api.wipmania.com/30.30.30.30: permission denied

我在这里看到了一个类似的问题链接,但仍然无法弄清楚。请告诉我正确的做法以及是否需要在appengine控制台上设置任何权限。

英文:

I'm getting a permission denied error when I make a call to another web service from within my go code.

part of the handler code on my server side go program:

client := http.Client{}
if resp, err := client.Get("http://api.wipmania.com/" + r.RemoteAddr); err != nil {
    c.Errorf("Error getting location from ip: %s", err.Error())
}

From the logs:

Error getting location from ip: Get http://api.wipmania.com/30.30.30.30: permission denied

I saw a similar qn here. Still unable to figure it out. Can you please tell me what is the right way to do this and if any permissions have to be set on the appengine console?

答案1

得分: 2

App Engine应用程序可以通过获取URL来与其他应用程序通信并访问网络上的其他资源。应用程序可以使用URL Fetch服务发出HTTP和HTTPS请求并接收响应。

尝试:

import (
    "fmt"
    "net/http"

    "appengine"
    "appengine/urlfetch"
)

func handler(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    client := urlfetch.Client(c)
    if resp, err := client.Get("http://api.wipmania.com/" + r.RemoteAddr); err != nil {
        c.Errorf("Error getting location from ip: %s", err.Error())
    }
    // ...
}
英文:

App Engine applications can communicate with other applications and can access other resources on the web by fetching URLs. An app can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses.

Try:

import (
    "fmt"
    "net/http"

    "appengine"
    "appengine/urlfetch"
)

func handler(w http.ResponseWriter, r *http.Request) {
    c := appengine.NewContext(r)
    client := urlfetch.Client(c)
    if resp, err := client.Get("http://api.wipmania.com/" + r.RemoteAddr); err != nil {
        c.Errorf("Error getting location from ip: %s", err.Error())
    }
    // ...
}

huangapple
  • 本文由 发表于 2012年8月13日 20:13:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/11934094.html
匿名

发表评论

匿名网友

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

确定