O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.65k stars 419 forks source link

Deprecation Warning when using O365 with Python 3.9+ due to pytz #986

Closed mkp-bartsch closed 11 months ago

mkp-bartsch commented 1 year ago

Hello,

I've been using the O365 library for my project and it's been really helpful. However, I've run into a warning related to the use of the pytz library for timezone handling.

Here's the warning message:

C:\Users\myUser\.virtualenvs\OutlookConnector-Ce9TnlpY\lib\site-packages\O365\utils\windows_tz.py:639: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  iana_tz.zone if isinstance(iana_tz, tzinfo) else iana_tz)

Path to error: C:\Users\myUser.virtualenvs\OutlookConnector-Ce9TnlpY\Lib\site-packages\O365\utils\windows_tz.py

Function / Code:

def get_windows_tz(iana_tz):
    """ Returns a valid windows TimeZone from a given pytz TimeZone
    (Iana/Olson Timezones)
    Note: Windows Timezones are SHIT!... no ... really THEY ARE
    HOLY FUCKING SHIT!.
    """
    timezone = IANA_TO_WIN.get(
        iana_tz.zone if isinstance(iana_tz, tzinfo) else iana_tz)
    if timezone is None:
        raise pytz.UnknownTimeZoneError(
            "Can't find Iana TimeZone " + iana_tz.zone)

    return timezone

I understand that this warning is due to the deprecation of pytz, which is replaced by the built-in zoneinfo module in Python 3.9+. Currently, I'm using Python 3.9 and it seems that O365 still uses pytz for timezone handling.

While this is currently a warning and not affecting the functionality of my program, it might lead to future issues if not addressed.

Could you please advise on this issue? Are there any plans to migrate from pytz to zoneinfo in the future versions of O365? Any updates or workarounds would be appreciated.

Thank you for your time and for maintaining this helpful library.

Best regards, Adrian

alejcas commented 1 year ago

Hi, I’m aware as this was reported earlier by someone else. I don’t have the time to fix this but PR are very welcome. Thanks

ponquersohn commented 1 year ago

@jancas here's the PR #994 . I've tested it locally but more testing is required. Happy to fix any issues.

alejcas commented 1 year ago

Thanks, I will add some comments.

ponquersohn commented 1 year ago

@mkp-bartsch Can you test the PR on windows?

mkp-bartsch commented 1 year ago

Hi, I'm very busy at work right now and won't be able to test the changes in the next few weeks. When I have come to it and this is still up to date, I'll get back to you. But thanks for the implementation!

kwilsonmg commented 11 months ago

@janscas given that the relevant PR was merged, this could be closed?

alejcas commented 11 months ago

Fixed in #994

mkp-bartsch commented 11 months ago

Thank you all for fixing!