reading data from stackoverflow rest api
Question: Playing around with the raspberry pi and python. so bear with me :)

When trying to decode the response data from the stackoverflow api I keep on
receiving the error `utf-8 codec can't decode byte 0x8b in position 1: invalid
start byte`

Here is the entire code that I have hacked up at the moment

    
    
    import http.client
    import json
    import zlib
    
    c = http.client.HTTPConnection('api.stackoverflow.com')
    c.request('GET', '/1.1/questions?answers=true&page=1&pagesize=5&tagged=sql')
    r = c.getresponse()
    
    compressedData = r.read()
    uncompressedData= zlib.decompress(compressedData, 15+32)
    
    data = str(compressedData, 'utf-8')
    print(data)
    

But the response data is encoded in utf-8 format? Not quite sure why this is
happening...


Answer: Your code looks fine but...

    
    
    data = str(compressedData, 'utf-8')
    

you're trying to decode the _compressed_ data. Try decoding the uncompressed
data :-)

