推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
simple2025
0D
V2EX  ›  Python

为什么我调用百度 api 的时候,有时候会返回 html 给我?正常都是 json, 然后错误的时候会跳到 "你访问的页面不存在"这个问题

  •  
  •   simple2025 · Oct 9, 2021 · 4818 views
    This topic created in 1856 days ago, the information mentioned may be changed or developed.

    这是为什么呀,我并发也不大呀,python 而已,一秒绝对没有 50 的呀,郁闷

    Supplement 1  ·  Oct 9, 2021
    正常情况下是这个 json
    ```
    {
    "status":"OK",
    "result":{
    "location":{
    "lng":120.389455,
    "lat":36.072227
    },
    "precise":0,
    "confidence":20,
    "level":"\u57ce\u5e02"
    }
    ```

    但是偶尔会返回一段 html, html 的样式很像 "你访问的页面不存在" 那个
    21 replies  •  2021-10-10 09:16:16 +08:00
    Trim21
    Trim21
    Oct 9, 2021 via Android❤️14
    1
    楼主可以考虑一下,如果是一个对你的情况一无所知的人,看到你的帖子能到的什么信息,能对你的问题提供什么帮助…
    moioooo
    moioooo
    Oct 9, 2021
    2
    哈哈哈,1 楼扎心了。
    还是建议描述问题给出图片,相应的接口连接、返回结果等等,有日志啥的也给一下。
    不然,网友也不能大海捞针帮你猜问题答案呀。
    oh
    oh
    Oct 9, 2021
    3
    直接上代码
    simple2025
    simple2025
    OP
    Oct 9, 2021
    4
    大佬们没遇到过就算了, 因为 v2 其实我也用的不是很熟呀
    simple2025
    simple2025
    OP
    Oct 9, 2021
    5
    因为这个问题,我现在判断了返回的 content-type, 如果是 html 就重试,郁闷了
    Oktfolio
    Oktfolio
    Oct 9, 2021
    6
    我见过接口在 4xx 5xx 错误,nginx 直接拦掉跳转错误页面了,估计百度这个也类似吧
    2i2Re2PLMaDnghL
    2i2Re2PLMaDnghL
    Oct 9, 2021❤️6
    7
    @chenqh 你这是*中文*用得不是很熟。
    simple2025
    simple2025
    OP
    Oct 9, 2021
    8
    @Oktfolio 可能吧, 但是就是很气,明明是 api 的错误,要给我返回个页面, 当然也可能是我用了 vpn 的问题,
    simple2025
    simple2025
    OP
    Oct 9, 2021
    9
    @2i2Re2PLMaDnghL 不是呀,v2 上传图片不方便呀
    2i2Re2PLMaDnghL
    2i2Re2PLMaDnghL
    Oct 9, 2021
    10
    @chenqh 你这个问题不需要任何图片就能说明。如果你觉得没图片说不清,那确实是中文表达不太熟练。
    另外,v2 上传图片很方便,充值即可。
    xiaowei0823
    xiaowei0823
    Oct 9, 2021 via iPhone
    11
    遇到过,的确是 API 的问题,自己做下判断吧
    Junzhou
    Junzhou
    Oct 9, 2021❤️1
    12
    @chenqh 接口返回页面有多种可能,不排除楼上说的 4xx,5xx,nginx 直接跳转错误页面,不过我更倾向于这是被风控了。

    还有就是不要生气,如果因为这种小问题,就很气,那怕不是早晚要气背过去。
    runo
    runo
    Oct 9, 2021 via iPhone
    13
    @2i2Re2PLMaDnghL 微博图床不用充值……
    lawsiki
    lawsiki
    Oct 9, 2021
    14
    开代理了?
    simple2025
    simple2025
    OP
    Oct 9, 2021
    15
    @lawsiki 是的开了代理,不开代理,上不了 v2 呀
    feitxue
    feitxue
    Oct 9, 2021
    16
    代理不要全局。。。按需代理。
    liuxu
    liuxu
    Oct 9, 2021❤️1
    17
    触发了百度的风控,一般都有,微博也有
    simple2025
    simple2025
    OP
    Oct 9, 2021
    18
    @liuxu 但是这种开放 api 也有风控,就有点奇怪了,关键是风控,居然是返回 html
    liuxu
    liuxu
    Oct 9, 2021
    19
    @chenqh 你看下你的请求头有没有 Accept: application/json,还是 Accept: */*,有的 client 工具默认是后者,会导致一些系统的异常页返回 html
    lishoujun
    lishoujun
    Oct 9, 2021
    20
    绝对没有 50 这个没有说服力。
    你申请的 quota 是多少呢?
    luckyc
    luckyc
    Oct 10, 2021
    21
    请求太快被拒绝了呗
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1562 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 13:51 · PVG 21:51 · LAX 05:51 · JFK 08:51
    ♥ Do have faith in what you're doing.