V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
gimp
V2EX  ›  Python

钉钉企业内部接口开发,使用 Python Post 数据报错 500

  •  
  •   gimp · 2018-06-07 17:22:48 +08:00 · 3356 次点击
    这是一个创建于 2144 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我用 Python 来处理钉钉的服务器端接口

    现在遇到一个问题,申请 token 后,get 请求都是能用的,post 数据就会报 500 错误

    之前发的接口数据字段多,怕参数哪里写的不对,于是使用了(获取用户待审批数量)接口测试找原因,这个接口只需要传递一个 userid

    https://open-doc.dingtalk.com/microapp/serverapi2/ui5305

    access_token = "xxxxxxxxxx"
    url = 'https://oapi.dingtalk.com/topapi/process/gettodonum?access_token=%s' % access_token
    
    data = {
        "userid": "manager4012"
    }
    
    headers = {
        'Content-Type': 'application/json'
    }
    
    r = requests.post(url, data=json.dumps(data), headers=headers)
    print(r.text)
    

    报错:

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
    <head><title>500 Internal Server Error</title></head>
    <body bgcolor="white"><script>
    with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","category=&userid=&aplus&yunid=&asid=AQAACADXmhdb3r3FKQAACACKRiLMGAxPpg==",id="tb-beacon-aplus",src="//g.alicdn.com/alilog/mlog/aplus_v2.js")
    </script>
    
    <h1>500 Internal Server Error</h1>
    <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</body>
    

    headers utf-8 也指定了,json 字符串也转换了

    纠结一两天,文档,demo 找了不少,很是不能理解一个 post 过去直接 500 错误,没思路了,特来求助

    第 1 条附言  ·  2018-06-11 16:22:34 +08:00

    500 错误确实是钉钉的接口挂了,等了两天,接口恢复了

    琢磨几天文档,心累

    1,两套API,两套文档,接口风格迥异,应该是两个团队开发的,文档中心两套共存,哪一个才是推荐版本呢

    2,域名(oapi.dingtalk.com)的接口有事件回调API,在注册自己的事件回调时,使用接口发送过去数据,钉钉访问我注册的回调URL,解析我回它的数据会提示“{"errcode":71009,"errmsg":"返回文本非success"}”,我使用钉钉开发者辅助工具(回调验证工具)填写参数后校验是成功的。另一套接口(https://eco.taobao.com/router/rest) 没有提供注册回调的接口

    文档姑且还能猜测一番,钉钉提供的接口调试工具与接口返回的结果不一致

    真的是:生无可恋.jpg 生无可恋.jpg

    4 条回复    2018-06-07 21:43:38 +08:00
    kunluanbudang
        1
    kunluanbudang  
       2018-06-07 18:41:10 +08:00 via Android
    500 是他们服务端问题
    gimp
        2
    gimp  
    OP
       2018-06-07 20:36:43 +08:00
    @kunluanbudang 是这么个理儿,但是... 他们不检测自己 API 可用性的吗...
    kinghui
        3
    kinghui  
       2018-06-07 20:50:08 +08:00
    不确定钉钉的 access_token 什么格式,但是这段代码唯一有问题的可能就是 access_token 没进行 URLEncode
    kunluanbudang
        4
    kunluanbudang  
       2018-06-07 21:43:38 +08:00 via Android
    @gimp

    国内的开放 API 都这尿性

    喂屎💩给别人吃,以后你会遇到更多


    不是 KPI 的事情,完全没动力做好
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1931 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.