Skip to content

Instantly share code, notes, and snippets.

@kmcquade
Created September 30, 2020 15:10
Show Gist options
  • Save kmcquade/8e74482c48b987675a8fba28d25031bf to your computer and use it in GitHub Desktop.
Save kmcquade/8e74482c48b987675a8fba28d25031bf to your computer and use it in GitHub Desktop.
Example of how to avoid TypeErrors with Boto3 scripts due to datetime errors
# add this class 
class DatetimeEncoder(json.JSONEncoder):
    def default(self, obj):
        try:
            return super().default(obj)
        except TypeError:
            return str(obj)

# Use this to print without errors. Notice the use of cls=DatetimeEncoder
print(json.dumps(results, indent=4, cls=DatetimeEncoder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment