我需要使用python中的request模块发布文件,该模块在文件名中包含unicode字符。在Python中使用requests.post在文件名中使用Unicode字符发送文件
我使用下面的代码:
url = "https://demo.php"
headers = {'Accept': 'application/vnd.ve.v1.0+json','API': 'aasadadas'}
file_up = {'filename': open(file_name, 'rb')}
upload_file_rest =requests.post(url,files=file_up,headers=headers,verify=False)
使用上面的代码,并通过文件名是 “指事字的.exe” 的时候,我得到以下异常:
'ascii' codec can't decode byte 0xc2 in position 26: ordinal not in range(128)
任何帮助真的很感激。
PS:我已经尝试下面的代码,它不工作对我来说:
file_up = {'filename': open(file_name.encode('utf-8'), 'rb')}