Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime.utcnow is deprecated in Python 3.12 #1021

Closed
tirkarthi opened this issue Jul 4, 2023 · 5 comments
Closed

datetime.utcnow is deprecated in Python 3.12 #1021

tirkarthi opened this issue Jul 4, 2023 · 5 comments

Comments

@tirkarthi
Copy link

datetime_now = datetime.datetime.utcnow()

Ref : python/cpython#103857

datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC. (Contributed by Paul Ganssle in gh-103857.)

@thehesiod
Copy link
Collaborator

that comes from botocore: https://github.com/boto/botocore/blob/1.29.161/botocore/signers.py#L593 please log there

@thehesiod
Copy link
Collaborator

btw, didn't follow the instructions in logging an issue :)

@thehesiod thehesiod closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2023
@tirkarthi
Copy link
Author

Sorry, I right clicked on the code line in GitHub UI and selected reference in new issue which seems to not show any template. I will check on the other repo. Thanks.

@thehesiod
Copy link
Collaborator

interesting, sounds like a github bug, here's the template btw: https://github.com/aio-libs/aiobotocore/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=

@phillipuniverse
Copy link

To make this slightly easier to find via Google, this is the Deprecation warning raised on Python 3.12:

    def add_auth(self, request):
        if self.credentials is None:
            raise NoCredentialsError()
>       datetime_now = datetime.datetime.utcnow()
E       DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

Tracked in botocore at boto/botocore#3088 which references a still-open issue at boto/boto3#3889.

In my case with pytest, fix is:

[tool.pytest.ini_options]
filterwarnings = [
    "error", # treat all warnings as errors
    "ignore:datetime.datetime.utcnow\\(\\) is deprecated and scheduled for removal in a future version.*:DeprecationWarning",
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants