Use "byte-like object" from urlopen.read with JSON? Use "byte-like object" from urlopen.read with JSON? python python

Use "byte-like object" from urlopen.read with JSON?


The content from read() is of type bytes so you need to convert it to a string before trying to decode it into a json object.

To convert bytes to a string, change your code to:urlopen('http://similarsitesearch.com/api/similar/ebay.com').read().decode("utf-8")


You need to examine the charset specified in the Content-Type header and decode by that before passing it to json.load*().


It worked well :

def myView(request):    encoding = request.read().decode("utf-8")    dic = json.loads(encoding)    print(dic)