我需要使用python的requests 下载一些文件,但是文件是中文名的
chrome调试看出来的文件名是
Content-Disposition:attachment; filename=%C9%F1%BC%B6%BB%F5%C0%C9.txt
requests 下载显示的却是乱码
import requests
url = 'http://www.23us.so/modules/article/txtarticle.php?id=156'
req = requests.head(url)
headers = req.headers
print( headers.get('Content-Disposition'))
>> attachment; filename=ÇàÔÆÏÉ·.txt
我试过设置req.encoding 没有效果
怎么把header中的文字恢复出来,requests中似乎没有相关方法
各位可以调试一下
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的文件名是使用 gb2312编码的,你解码也需要设置 按照gb2312 解码,如果按照utf-8解码,就会出现乱码。可能你设置过的解码,默认按照utf-8解码的