doudou8783 2019-05-10 09:09
浏览 79
已采纳

从reddit api获取时如何修复“ Error 503 CDN error”?

for learning purposes I'm building a command line tool using golang, this cli fetches the top ten posts from GameDeals subreddit using the following api:

https://www.reddit.com/r/gamedeals/hot.json?limit=10

When I send the request I got as response a 503 Service Unavailable and some HTML:

<img src=//s3.amazonaws.com/redditstatic/heavy-load.png alt="">
<h2>Our CDN was unable to reach our servers</h2>
Please check <a href="http://www.redditstatus.com/">www.redditstatus.com</a> if you consistently get this error.

I don't understand why if I fires the request from a browser I got the json expected and instead a 503 error from my cli.

Here's my code that performs the request:

    address := fmt.Sprintf("%s/hot.json?limit=%d", redditBaseURL, 10)

    req, err := http.NewRequest("get", address, nil)
    if err != nil {
        return err
    }

    req.Header.Set("User-Agent", userAgent)

    res, err := client.Do(req)
    if err != nil {
        return err
    }

    defer res.Body.Close()

    result, err := ioutil.ReadAll(res.Body)
    if err != nil {
        return err
    }

    fmt.Println(string(result))

Am I missing something?

  • 写回答

1条回答 默认 最新

  • duanchun2349 2019-05-10 11:51
    关注

    Changed from https to http and now is working

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试