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

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

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境