import urllib2
import requests
url = 'exmaple.com'
headers = {
"Authorization": "Basic xxxx",
"Range": "bytes=0-"
}
req = urllib2.Request(url, headers=headers)
resp = urllib2.urlopen(req)
print resp.info()
r = requests.get(url, headers=headers)
print r.headers
assert resp.info()['ETag'] == r.headers['ETag']
Date: Sat, 14 Jan 2017 09:39:50 GMT
Server: Apache
Last-Modified: Sat, 14 Jan 2017 09:39:49 GMT
ETag: "e91103-10e04f7-5460abb4743a3"
Accept-Ranges: bytes
Content-Length: 17695991
Vary: Accept-Encoding
Content-Range: bytes 0-17695990/17695991
Connection: close
Content-Type: text/plain
{'Content-Encoding': 'gzip', 'Transfer-Encoding': 'chunked', 'Accept-Ranges': 'bytes', 'Vary': 'Accept-Encoding', 'Keep-Alive': 'timeout=5, max=128', 'Server': 'Apache', 'Last-Modified': 'Sat, 14 Jan 2017 09:39:49 GMT', 'Connection': 'Keep-Alive', 'ETag': '"e91103-10e04f7-5460abb4743a3"', 'Date': 'Sat, 14 Jan 2017 09:39:50 GMT', 'Content-Type': 'text/plain'}
我也知道肯定是两次发送的请求header不一样。。。现在总算解决了。。