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

2021-05-28 16:39:22 +08:00
 leartang
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


大佬救命...
1356 次点击
所在节点    Python
6 条回复
frostming
2021-05-28 16:40:45 +08:00
post 的话,requests.post(url, json=empinfo)就行了啊,为啥要自己 dumps
InkAndBanner
2021-05-28 17:07:22 +08:00
编码问题 unicode
renmu123
2021-05-28 17:09:46 +08:00
r = response.post(url)
r.json()
leartang
2021-05-28 17:45:04 +08:00
@frostming 改了还是不行,关键是我用原来的早上成功过一次。这样创建组织架构中文也都正常🤣🤣🤣
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
2021-05-28 22:21:15 +08:00
更正上面,是 requests.post

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/779860

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX