python requests 编码问题
Posted wanderingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python requests 编码问题相关的知识,希望对你有一定的参考价值。
url = host + path
headers = ...
data = ...
files = ...
files两种类型: 字典和 元组
"field1" : ("filename1", open("filePath1", "rb")),
"field2" : ("filename2", open("filePath2", "rb"), "image/jpeg"),
"field3" : ("filename3", open("filePath3", "rb"), "image/jpeg", "refer" : "localhost")
字段对应:"字段名": ("filename","fileobject", "content-type", "headers")
或者
"field1" : open("filePath1", "rb"),
"field2" : open("filePath2", "rb"),
"field3" : open("filePath3", "rb")
元组形式:
[
("field1" , ("filename1", open("filePath1", "rb"))),
("field2" , ("filename2", open("filePath2", "rb"), "image/jpeg")),
("field3" , ("filename3", open("filePath3", "rb"), "image/jpeg", "refer" : "localhost"))
]
字段对应:["字段名", ("filename","fileobject", "content-type", "headers")]
data = requests.post(url,files=files,data=data_dict,headers=headers)
print(data.content.decode("utf-8"))
注: 上述可能filename不支持中文名,可以 D:\Users\jiangbo.xu\AppData\Local\Programs\Python\Python35\Lib\site-packages\urllib3\fields.py 50行左右
value = '%s*=%s' % (name, value) 改成 value = '%s=%s' % (name, value)
以上是关于python requests 编码问题的主要内容,如果未能解决你的问题,请参考以下文章
python 用requests获取网页源代码为啥中文显示错误
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段