Tag Archives: Python Error

[Solved] Python Error: datetime.datetime is not JSON serializable

Question:

The project is developed with Django, and the returned data contains a time field. When JSON. Dumps(), it will prompt: datetime. Datetime is not JSON serializable

Solution:

import json  
from datetime import date, datetime
  
class DateEncoder(json.JSONEncoder):  
    def default(self, obj):  
        if isinstance(obj, datetime):  
            return obj.strftime('%Y-%m-%d %H:%M:%S')  
        elif isinstance(obj, date):  
            return obj.strftime("%Y-%m-%d")  
        else:  
            return json.JSONEncoder.default(self, obj)

When using it, return will do

return HttpResponse(json.dumps(rows, cls=DateEncoder))

Python Error: “failed to execute pyi_rth_pkgres”

reference resources: https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages

First, uninstall pyinstaller, then download and install it from GitHub

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Bloggers solve the problem through the above methods