我用aiohttp.FormData()
发送一个文件到Telegram聊天
bytes_io = BytesIO(b"test file content 1")
file_content = bytes_io.getvalue()
file_name = "тест_1.txt"
async with aiohttp.ClientSession() as session:
post_file_data = aiohttp.FormData()
post_file_data.add_field(
"chat_id", json.dumps(chat_id),
content_type='application/json'
)
post_file_data.add_field(
"document", file_content, filename=file_name,
)
response = await session.post(
url_doc, proxy=full_proxy_url, ssl=False,
data=post_file_data,
)
一切正常,但文件名只能是ASCII字符。否则文件名将变得不可读(例如:"%D1%82%D0%B5%D1%81%D1%82_1.txt")。
如何使文件名正常显示任何字符?
问题已解决。应该这样做:
post_file_data = FormData(quote_fields=False)
...