1

PreFile :

PreFile = {
  "Preferences": {
    "Quotas": {
       "Rate limit": 0,
       "Reset time": "2020-10-28 10:57:21.482911"
       }
    }
  }

My code:

    PrefFile["Preferences"]["Quotas"]["Reset time"] = data_option
       with open(Preferences_Path, 'w') as Preferences_File:
           json.dump(PrefFile, Preferences_File, indent=4, sort_keys=True)

 
    PreResetTime = PreFile["Preferences"]["Quotas"]["Reset time"]
    ResetTime = datetime.strptime(PreResetTime, '%Y-%m-%d %H:%M:%S.%f')

Error output: TypeError: Object of type datetime is not JSON serializable

  File "main_functions.py", line 158, in updating_preferences
    json.dump(PrefFile, Preferences_File, indent=4, sort_keys=True)

I'm going to use ResetTime later in the program

if(ResetTime < (time_now - timedelta(hours=24))):
      code...
1

2 Answers 2

1

For this line:

PrefFile["Preferences"]["Quotas"]["Reset time"] = data_option

Change to this or similar:

PrefFile["Preferences"]["Quotas"]["Reset time"] = data_option.isoformat()

https://docs.python.org/library/datetime.html#datetime.datetime.isoformat

Sign up to request clarification or add additional context in comments.

Comments

0

convert your data_option to string before updating PrefFile["Preferences"]["Quotas"]["Reset time"] Answer by @Shijith

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.