python使用aiohttp模块,调用Jira API 接口请求提交附件,文件名乱码
- 我使用python中aiohttp模块将文件提交到Jira附件中,提交的文件名为乱码,内容正常,
Jira测试地址http://193.112.46.206:8080,admin/123456
上传附件接口文档地址:https://docs.atlassian.com/so...{issueIdOrKey}/attachments-addAttachment - 代码如下
import base64import aiohttp
import asyncio
from aiohttp import FormData
def base64_encode(string):
encode_string = base64.b64encode(string.encode('utf-8'))
return str(encode_string,"utf-8")
async def main():
url = 'http://193.112.46.206:8080/rest/api/2/issue/JIRA-1/attachments'
data = FormData()
data.add_field('file',
open('未命名.md', 'rb'),
filename=u'未命名.md',
content_type='application/md')
token = "Basic " + base64_encode("admin:123456")
headers = {'X-Atlassian-Token': 'no-check',"Authorization":token}
print(url)
async with aiohttp.ClientSession() as session:
async with session.post(url, data=data,headers=headers,) as resp:
print(resp.status)
print(await resp.text())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
执行可以上传,但是文件名变成了乱码
{..."filename":"%E6%9C%AA%E5%91%BD%E5%90%8D.md",
...}
- 通过curl调用原生接口上传,附件的名称为中文
curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=@未命名.md" http://193.112.46.206:8080/rest/api/2/issue/JIRA-1/attachments
- aiohttp封装文件数据后,为何调用接口上传返回的是乱码,初步判定是aiohttp没有封装对,
求助大神~~
回答:
from urllib.parse import unquoteprint(unquote("%E6%9C%AA%E5%91%BD%E5%90%8D.md"))
未命名.md
可以搜搜urlencode了解原因。
以上是 python使用aiohttp模块,调用Jira API 接口请求提交附件,文件名乱码 的全部内容, 来源链接: utcz.com/p/937648.html