Python请求模块-仅发送指定的头

Python请求模块-仅发送指定的头,python,http-headers,python-requests,Python,Http Headers,Python Requests,我需要发送一个post请求到一个只有“主机”和“内容长度”标题的web服务器。我在传递给请求模块的字典中指定了这两个头,但它添加了“接受”、“接受编码”, “用户代理”标题 Python代码: headers = {'Content-Length': content_length, 'Host': 'Server-1:8080'} r = requests.post(url, data=data, headers=headers) print(r.request.headers) 实际发送的请

我需要发送一个post请求到一个只有“主机”和“内容长度”标题的web服务器。我在传递给请求模块的字典中指定了这两个头,但它添加了“接受”、“接受编码”, “用户代理”标题

Python代码:

headers = {'Content-Length': content_length, 'Host': 'Server-1:8080'}
r = requests.post(url, data=data, headers=headers)
print(r.request.headers)
实际发送的请求标头:

{'Accept': '*/*', 'Host': 'Server-1:8080', 'Content-Length': '3072', 'User-Agent': 'python-requests/2.6.0 CPython/3.4.1 Windows/7', 'Connection': 'keep-alive, 'Accept-Encoding': 'gzip, deflate'}
如何限制请求模块发送的头?

从阅读来看,这些是会话级参数,您可以通过将其值设置为
None
来强制忽略它们

headers = {'Content-Length': content_length, 'Host': 'Server-1:8080',
           'User-Agent': None, 'Connection': None, 'Accept-Encoding': None}