Skip to content

Instantly share code, notes, and snippets.

@alces
Created September 10, 2019 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/913c1f57c1c62d34166ca31699856b97 to your computer and use it in GitHub Desktop.
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)
#!/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