Problem with python + json + urllib error json.decoder.JSONDecodeError

0

I can not use json and urllib I get an error, I'm finding that the error is because of the system, I use windows! I already researched a lot and I do not see a solution to this mistake. The code is very simple:

    import json
from urllib.request import urlopen, Request


with urlopen('http://python.org/') as response:
   html = response.read().decode('utf-8')

print(html)

data = json.loads(html)

print(json.dumps(data, indent=2))

error occurs:

    File "D:\Marcus\Projetos\Programação\Python\Study\Json\HOWTO Fetch Internet Resources\urllib_json.py", line 10, in <module>
    data = json.loads(html)
  File "C:\Program Files\Python36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\Python36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\Python36\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Use: Python 3.6.5, Windows 10

If someone can help me, thank you!

    
asked by anonymous 17.08.2018 / 16:33

0 answers