How do I get HTTP trailer response headers with python? I am using requests.get and I am unable to get some of the X-Content-Type or X-Status. When I use curl with -i though, I get these responses. Do I need to send a specific header or parameter? I tried sending TE: trailers but it doesnt seem to do anything.
Some sample code:
import requests
url = "some_api_endpoint"
params = {"param1": "val1"}
headers = {"Accept": "application/json", "TE": "trailers"}
response = requests.get(url, params=params, headers=headers, verify=False)
print("Status: {}".format(response.status_code))
print("Content: {}".format(response.content.decode('utf-8')))
print("Headers: {}".format(response.headers))
print("Reason: {}".format(response.reason))
Output:
Status: 200
Content:
Headers: {'Connection': 'close', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked'}
Reason: OK
curl command
curl -k -i <url>?<params> -H 'Accept: application/json'
Output:
TP/1.1 200 OK
Connection: close
Content-Type: application/json
Transfer-Encoding: chunked
X-Status: Some Error
I would like to get the Some Error or just even the header X-Status above from python. Basically got the 200 from the server and while streaming some of the response, it hit an error in the middle, causing the error. Unfortunately, I cant get this message easily in python.