Issue
Summarize the problem: Uncompressed JSON payload updates successfully. However, compressed JSON fails to upload to the website.(using Python requests module)
2. I am trying to POST comparatively large JSON data(1 MB +) to a website I wish to compress the JSON data(stream) and post it to a wesite. The catch is- compressed JSON returns success code, but data is not reflected on the website. On the contrary, the same JSON data is making through when not compressed.
3. When appropriate, show some code:
Works fine:
payload without compression - goes though to website without issues:
payload={"eventType": "check", "status": "Fail","testCategory": "Test"}
headers = {‘Content-Type’: ‘application/json’,‘X-Insert-Key’: ‘XXXXXXX’}
r = requests.post(url, data=json.dumps(payload), headers=headers)
NOT working
the payload that is compressed not making it to the website:
payload={"eventType": "check", "status": "Fail","testCategory": "Test"}
headers = {‘Content-Type’: ‘application/json’,‘X-Insert-Key’: ‘XXXXXXX’, ‘Content-Encoding’:‘gzip’}
request_body = zlib.compress(json.dumps(payload))
r = requests.post(url, data=request_body, headers=headers)
I am banging my head around but it seems I am missing on something subtle. Any help/tips will be highly appreciated
Solution
Changing - ‘Content-Encoding’:‘gzip’} to ‘Content-Encoding’:‘deflate’} fixed the issue for me Note: This answer is specific to New Relic custom events
Answered By - pythondev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.