Problem with the opening of JSON



  • Subject code:

     def check_mail(self, mail):
         f = open("base.json", 'r')
         text = f.read()
         result = json.loads(text)
         return result
    

    And conclusion:

    Traceback (most recent call last):
      File "/Users/Vadim/Documents/Python/Houme Task/reg.py", line 42, in <module>
        print(data.check_mail("sokle@gmail"))
      File "/Users/Vadim/Documents/Python/Houme Task/reg.py", line 32, in check_mail
        return json.loads(text)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads
        return _default_decoder.decode(s)
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 342, in decode
        raise JSONDecodeError("Extra data", s, end)
    json.decoder.JSONDecodeError: Extra data: line 1 column 73 (char 72)
    

    MacOS/CPython 3.5

    The data recorded in the file in such a format:

    {"sokle@gmail.com": ["Pavel", "nejcenwvewnvlewn"]}
    


  • Maybe the reason you're trying to decode the plural. JSON?
    Works:

    >>> import json
    >>> json.loads('{}')
    {}
    

    But:

    >>> json.loads('{}{}')
    Traceback (most recent call last):
      File "<pyshell#4>", line 1, in <module>
        json.loads('{}{}')
      File "S:\Python\lib\json\__init__.py", line 319, in loads
        return _default_decoder.decode(s)
      File "S:\Python\lib\json\decoder.py", line 342, in decode
        raise JSONDecodeError("Extra data", s, end)
    json.decoder.JSONDecodeError: Extra data: line 1 column 3 (char 2)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2