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
leartang
V2EX  ›  Python

企业微信通讯录同步创建用户姓名不显示中文求助

  •  
  •   leartang · 2021-05-28 16:39:22 +08:00 · 1345 次点击
    这是一个创建于 1064 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python 3.9 用的 requests.post

    empinfo = {
    "userid": "%s" %loginid,
    "name": "%s" %name,
    "mobile": "%s" %mobile,
    "department": "%s" %deptid,
    }
    send_empinfo = (bytes(json.dumps(empinfo), 'utf-8'))


    json.dumps 解析为
    b'{"userid": "55555", "name": "\\u6d4b\\u8bd5", "mobile": "13912345678", "department": "888888"}'

    企业微信的姓名显示为 \u6d4b\u8bd5


    大佬救命...
    6 条回复    2021-05-28 22:21:15 +08:00
    frostming
        1
    frostming  
       2021-05-28 16:40:45 +08:00
    post 的话,requests.post(url, json=empinfo)就行了啊,为啥要自己 dumps
    InkAndBanner
        2
    InkAndBanner  
       2021-05-28 17:07:22 +08:00
    编码问题 unicode
    renmu123
        3
    renmu123  
       2021-05-28 17:09:46 +08:00
    r = response.post(url)
    r.json()
    leartang
        4
    leartang  
    OP
       2021-05-28 17:45:04 +08:00 via Android
    @frostming 改了还是不行,关键是我用原来的早上成功过一次。这样创建组织架构中文也都正常🤣🤣🤣
    cz5424
        5
    cz5424  
       2021-05-28 22:20:32 +08:00
    标准编码问题,楼主太会绕弯了; print('\u6d4b\u8bd5')
    发 json
    data = {}
    r = response.post(url, json=data)
    收 json
    r = response.post(url)
    r.json()
    cz5424
        6
    cz5424  
       2021-05-28 22:21:15 +08:00
    更正上面,是 requests.post
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2734 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:16 · PVG 13:16 · LAX 22:16 · JFK 01:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.