I am attemping to get data from an HTTP post using the following snippet:
import request
# Using @ to signify personal info
url = "@@@@@"
querystring = {"user":"@@@@@yahoo.com"}
headers = {
'token': 1234,
'content-type': "application/x-www-form-urlencoded",
'host': "@@@",
'connection': "Keep-Alive",
'accept-encoding': "gzip",
'content-length': "0",
'cache-control': "no-cache"
}
response = requests.request("POST", url, headers=headers, params=querystring)
print(response.text)
I get the following result (the ... is the rest of the 'data' string):
{'data': 'H4sIAAAAAAAAAO...T7R358EQT/u3/8D+8Rtv5/DwIA', 'error_code': 0, 'response_desc': 'SUCCESS'}
Unlike all other questions I have found on stackoverflow, the gzipped data of interest lives within a json response. The json object itself is not compressed. I have tried
zlib.decompress(response.json().get("data"),15 + 32)
But get the error
TypeError: a bytes-like object is required, not'str'
Am I going about handling the decoding correctly? I see plenty of documentation on decoding a gz file but this is just a string that is gz compressed.
Additional attempt: trying
zlib.decompress(response.json().get("data").encode(), 16 + zlib.MAX_WBITS)
Gives me the error:
incorrect header checkk
zlib.decompress(response.json().get("data").encode(), 15 + 32)zlib.decompress(response.json().get("data").encode(), 16 + zlib.MAX_WBITS)The previous header was incorrect it seems.