我正在尝试在 Google App Engine 的 Golang 中创建一个 Reddit API。我的代码:
package RedditAPI
import(
"appengine"
"encoding/json"
"io/ioutil"
"net/http"
"appengine/urlfetch"
"time"
"net/url"
)
func GetTopSubmissions(c appengine.Context){
one, two:=Call(c, "http://www.reddit.com/r/Bitcoin/top.json", "POST", nil);
c.Infof("%v, %v", one, two);
}
func Call(c appengine.Context, address string, requestType string, values url.Values)(map[string]interface{}, error){
req, err:=http.NewRequest("GET", address, nil)
if err!=nil{
c.Infof("Request: %v", err)
return nil, err
}
req.Header.Add("User-Agent", "This is a very creative name for a Reddit bot v1.0 by /u/username")
c.Infof("%v", req.Header.Get("User-Agent"))
c.Infof("%v", req)
c.Infof("%v", req.UserAgent())
duration, err:= time.ParseDuration("60s")
tr := &urlfetch.Transport{Context: c, Deadline: duration}
resp, err:=tr.RoundTrip(req)
if err != nil {
c.Infof("Post: %v", err)
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
c.Infof("ReadAll: %v", err)
return nil, err
}
result := make(map[string]interface{})
err = json.Unmarshal(body, &result)
if err != nil {
c.Infof("Unmarshal: %v", err)
c.Infof("%s", body)
return nil, err
}
return result, nil
}
退货
2013/05/23 03:00:34 Unsolicited response received on idle HTTP channel starting with "H"; err=<nil>
2013/05/23 03:01:42 INFO: &{GET http://www.reddit.com/r/Bitcoin/top.json HTTP/1.1 1 1 map[User-Agent:[This is a very creative name for a Reddit bot v1.0 by /u/username]] <nil> 0 [] false www.reddit.com map[] <nil> map[] <nil>}
2013/05/23 03:01:42 INFO: This is a very creative name for a Reddit bot v1.0 by /u/username
2013/05/23 03:01:42 INFO: map[error:429], <nil>
INFO 2013-05-23 03:01:42,720 server.py:584] default: "GET / HTTP/1.1" 200 81
此错误的原因可能是什么?