Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
调用
reply.download_url(download_code, msg_id)换取消息附件下载地址时,钉钉接口/v1.0/robot/messageFiles/download会返回400 Missingbody错误。原因:
Reply.download_url调用http_json发送 POST 请求时未携带Content-Type: application/json请求头,标准库urllib.request在有请求体但未指定Content-Type时会默认使用application/x-www-form-urlencoded,导致钉钉服务端无法解析 JSON 请求体而报错400 Missingbody。修改内容
src/dingtalk_channel_sdk/reply.py:在Reply.download_url请求头中显式补充"Content-Type": "application/json"(与仓库内其余http_json调用保持一致)。tests/test_e7_media.py:新增test_download_url_sends_json_content_type单测,验证请求携带Content-Type: application/json、x-acs-dingtalk-access-token及正确的 JSON 请求体(若缺失application/json则模拟返回400 Missingbody)。测试验证
pytest全量单测(139 项)全部通过。