Skip to content

Fix use of deprecated datetime.utcnow() function #93

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

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

WFT
Copy link
Contributor

@WFT WFT commented Jun 6, 2024

Hi! When using this library with Python 3.12, you get a deprecation warning. Luckily it's easily fixed.

The warning:

  /usr/local/lib/python3.12/site-packages/appstoreserverlibrary/api_client.py:469: 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).
    future_time = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)

You can see that warning when running the tests in this repository with a sufficiently new Python (python3 -m unittest). Luckily the replacement is easy. I've used datetime.timezone.utc instead of datetime.UTC because that alias was only introduced in 3.11.

This function has been deprecated in Python 3.12, as seen in this warning:
```
  /usr/local/lib/python3.12/site-packages/appstoreserverlibrary/api\_client.py:469: 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).
    future\_time = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
```

You can see that warning when running the tests in this repository with a sufficiently new Python (`python3 -m unittest`). Luckily the replacement has been available for a while! I've used datetime.timezone.utc instead of datetime.UTC because that alias was only introduced in 3.11.
WFT added a commit to WFT/app-store-server-library-python that referenced this pull request Jun 6, 2024
This use of the cryptography package generates a warning, seen below.

```
/Users/Will/dev/forks/app-store-server-library-python/tests/util.py:22: CryptographyDeprecationWarning: Curve argument must be an instance of an EllipticCurve class. Did you pass a class by mistake? This will be an exception in a future version of cryptography.
  public_key = ec.generate_private_key(ec.SECP256R1).public_key().public_bytes(encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo).decode()
```

I noticed this while preparing apple#93 & thought I'd toss this up as well. It passes the tests on my local machine, now without this warning.
Copy link
Collaborator

@alexanderjordanbaker alexanderjordanbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the improvement

@alexanderjordanbaker alexanderjordanbaker merged commit 7d9c1c9 into apple:main Jun 9, 2024
5 checks passed
@WFT
Copy link
Contributor Author

WFT commented Jun 10, 2024

Sure thing!

@WFT WFT deleted the fix-warning branch June 10, 2024 15:08
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

Successfully merging this pull request may close these issues.

2 participants