我使用Python的请求库向服务器发出了一个请求。代码如下(它使用适配器,因此需要匹配某种模式):
def getRequest(self, url, header):
"""
implementation of a get request
"""
conn = requests.get(url, headers=header)
newBody = conn.content
newHeader = conn.headers
newHeader['status'] = conn.status_code
response = {"Headers" : newHeader, "Body" : newBody.decode('utf-8')}
self._huddleErrors.handleResponseError(response)
return response
我正在解析的标头参数是这个
{'Authorization': 'OAuth2 handsOffMyToken', 'Accept': 'application/vnd.huddle.data+json'}
然而我从服务器得到的是一个XML响应。经过检查fiddler后发现发送的请求如下:
Accept-Encoding: identity
Accept: */*
Host: api.huddle.dev
Authorization: OAuth2 HandsOffMyToken
Accept: application/vnd.huddle.data+json
Accept-Encoding: gzip, deflate, compress
User-Agent: python-requests/1.2.3 CPython/3.3.2 Windows/2008ServerR2
我们可以看到有两个Accept Headers!requests库添加了这个Accept:*/*头,这导致服务器出现问题。请问有人知道我怎样才能停止这个操作吗?
requests
或使用b'Accept'
作为解决方法。 - jfs