Created
September 10, 2019 09:17
-
-
Save alces/913c1f57c1c62d34166ca31699856b97 to your computer and use it in GitHub Desktop.
Fetch compressed content from an URL (e.g., usable with Lenses REST API)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Get compressed URL content | |
import gzip | |
import StringIO | |
import urllib2 | |
req = urllib2.Request('http://my.lenses.url/api/alerts', | |
headers = { | |
'Accept-encoding': 'gzip', | |
'Content-Type': 'application/json', | |
'X-Kafka-Lenses-Token': 'my-service-account-token'}) | |
resp = urllib2.urlopen(req).read() | |
buf = StringIO.StringIO(resp) | |
print gzip.GzipFile(fileobj = buf).read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment