A
A
AdvoKappa2020-05-31 22:11:19
Python
AdvoKappa, 2020-05-31 22:11:19

Json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0), how to fix?

Here is the entire Python code, discord.py:

working_directory = os.getcwd()

file_path = working_directory + '\\Level.png'

@bot.event
async def on_message(message):

    if message.content == '!Коины':
        channel = message.channel
        await channel.send(f'Ваше кол-во коинов {coins}')

with open(file_path, 'r') as f:
    users = json.load(f)

    await update_data(users, message.author)
    await add_coins(users, message.author, 100000)

with open(file_path, 'w') as f:
    json.dump(users)

@bot.event
async def on_member_join(member):
    with open(file_path, 'r') as f:
        users = json.load(f)

    channel = bot.get_channel(707973541899010119)

    role = discord.utils.get(member.guild.roles, id = 709424815152431104)

    await member.add_roles(role)
    await channel.send(embed = discord.Embed(description = f'Новое @{member.name} яблоко в саду!Тут ты можешь найти людей для игры в разные игры! Я создал комнаты почти для каждой игры! Также ознакомься с правилами на канале #правила!Чем больше сообщений ты напишешь, тем больше ранк у тебя будет. Community - 10 LVL, Premium Community - 15 LVL, Best Community - 20 LVL, Удачи!'))

    await update_data(users, member)

with open(file_path,'w') as f:
    json.dump(users, f)

async def update_data(users, user):
    if not user.id in users:
        users[user.id] = {}
        users[user.id]['coins'] = 0

async def add_coins(users, user, coins):
    users[user.id]['coins'] += coins

Here is the whole error:
Traceback (most recent call last):
  File "bot_Discord.py", line 43, in <module>
    users = json.load(f)
  File "C:\Users\stas\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\stas\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\stas\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\stas\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-05-31
@AdvoKappa

Are you trying to get json from a .png file? Read what .json and .png files are and find the differences between them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question