【发布时间】:2015-09-18 11:51:32
【问题描述】:
我当前使用的一个 API 指定我需要一个特殊的内容类型字符串。我不知道如何在 python-requests 库中设置它
【问题讨论】:
-
只设置标题?仅当您使用
data、files或json作为requests.post()调用的参数时,requests才会设置Content-Type,并且您始终可以使用headers字典覆盖它。
我当前使用的一个 API 指定我需要一个特殊的内容类型字符串。我不知道如何在 python-requests 库中设置它
【问题讨论】:
data、files 或 json 作为 requests.post() 调用的参数时,requests 才会设置 Content-Type,并且您始终可以使用 headers 字典覆盖它。
import requests
headers = {'Content-type': 'content_type_value'}
r = requests.get(url, headers=headers)
【讨论】: