'json.decoder.JSONDecodeError : Expecting value: line 1 column 1

I'm trying to create a simple UserAgentHandler for my Telegram Bot that works with json ; But when I try to load empty json file I got this error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I've try to open file with {"bot" : "none"} but that way wasn't work! here my code:

import json
class connect:
    def __init__(self , name) -> None:
        self.open = open(name , '+at')
    
        try:
            self.dict = json.loads(self.open.read())
        except json.decoder.JSONDecodeError:
            self.open.write('{"Bot" : "none"}')  
connect('test.json')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source