Comments (16)
ok, closing this and will release next version soon
from python-o365.
connection.patch
Oh actually this works:
self._timezone: ZoneInfo = ZoneInfo(time.localtime().tm_zone)
And get_windows_tz complies with it:
from O365 import Account, MSGraphProtocol
protocol = MSGraphProtocol(api_version="beta")
from O365.utils import get_windows_tz
get_windows_tz(protocol.timezone)
'GTB Standard Time'
So that is your fix apparently ;)
from python-o365.
tzlocal dropped pytz completely.
I think you are using an old version
We now enforce tzlocal >=5.0
https://github.com/regebro/tzlocal?tab=readme-ov-file#api-change
from python-o365.
Maybe @Invincibear might have some insight into this?
from python-o365.
I haven't touched that part of the codebase, but sounds like #1051 would fix it, eventually. I would look at the Protocol
class to see if it defines keyword_data_store
, it looks like the code is assigning that dict a value but was the dict ever created before adding an item to it?
from python-o365.
That is probably my fault… I have to look into it a bit. I’ve run some test and all worked, let me see. I’ll report back
from python-o365.
Thanks @alejcas. No worries and no rush, I’ll hold back the update in the meantime ;)
from python-o365.
Ps. Probably worth to mention that I’m not using the “user” account but the auth_flow_type=‘credentials’
from python-o365.
Fixed!
Can you try again? I'll release a new version if all works
from python-o365.
Almost there:
In [1]: import os
...: from O365 import Account, MSGraphProtocol
...: protocol = MSGraphProtocol(api_version="beta")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line 5
3 from urllib import parse
4 import csv
----> 5 protocol = MSGraphProtocol(api_version="beta") # MSGraphProtocol defaults to v1.0 api version
File ~/development/python-o365/O365/connection.py:245, in MSGraphProtocol.__init__(self, api_version, default_resource, **kwargs)
243 self.keyword_data_store['file_attachment_type'] = '#microsoft.graph.fileAttachment'
244 self.keyword_data_store['item_attachment_type'] = '#microsoft.graph.itemAttachment'
--> 245 self.keyword_data_store['prefer_timezone_header'] = f'outlook.timezone="{get_windows_tz(self._timezone)}"'
246 self.max_top_value = 999
File ~/development/python-o365/O365/utils/windows_tz.py:635, in get_windows_tz(iana_tz)
628 def get_windows_tz(iana_tz: ZoneInfo) -> str:
629 """ Returns a valid windows TimeZone from a given pytz TimeZone
630 (Iana/Olson Timezones)
631 Note: Windows Timezones are SHIT!... no ... really THEY ARE
632 HOLY FUCKING SHIT!.
633 """
634 timezone = IANA_TO_WIN.get(
--> 635 iana_tz.key if isinstance(iana_tz, tzinfo) else iana_tz)
636 if timezone is None:
637 raise ZoneInfoNotFoundError(f"Can't find Iana timezone: {iana_tz.key}")
AttributeError: '_PytzShimTimezone' object has no attribute 'key'
python-o365 is using tzlocal
methods, which is using the (now deprecated) pytz
which returns a <class 'pytz_deprecation_shim._impl._PytzShimTimezone'>
that doesn't get handled well by the code.
You might want to stop using pytz there and do something like:
import time
[...]
self._timezone: ZoneInfo = time.localtime().tm_zone
as time.localtime().tm_zone
returns CET
strings that the code should understand:
time.localtime().tm_zone
'EET'
type(time.localtime().tm_zone)
str
And this should work in Windows as well (I hope at least). [I am on a Mac and can't test that]
from python-o365.
Ok if I you use time.localtime().tm_zone
this is what happens later on:
File ~/development/python-o365/O365/drive.py:1609, in Drive._update_data(self, data)
1607 local_tz = self.protocol.timezone
1608 print(local_tz)
-> 1609 self.created = parse(created).astimezone(local_tz) if created else None
1610 self.modified = parse(modified).astimezone(local_tz) if modified else None
TypeError: tzinfo argument must be None or of a tzinfo subclass, not type 'str'
Any chance you can get away without using this get_windows_tz
function if you use that tm_zone on Windows ?
Even if I try to do
import time
import datetime
[...]
self._timezone: ZoneInfo = datetime.tzinfo(time.localtime().tm_zone)
Then later on I get in trouble here:
File ~/development/python-o365/O365/utils/windows_tz.py:635, in get_windows_tz(iana_tz)
628 def get_windows_tz(iana_tz: ZoneInfo) -> str:
629 """ Returns a valid windows TimeZone from a given pytz TimeZone
630 (Iana/Olson Timezones)
631 Note: Windows Timezones are SHIT!... no ... really THEY ARE
632 HOLY FUCKING SHIT!.
633 """
634 timezone = IANA_TO_WIN.get(
--> 635 iana_tz.key if isinstance(iana_tz, tzinfo) else iana_tz)
636 if timezone is None:
637 raise ZoneInfoNotFoundError(f"Can't find Iana timezone: {iana_tz.key}")
AttributeError: 'datetime.tzinfo' object has no attribute 'key'
from python-o365.
You might want to stop using pytz there and do something like:
We already dropped support for pytz. Are you using it?
from python-o365.
So that is your fix apparently ;)
I don't see the fix...
self._timezone: ZoneInfo = ZoneInfo(time.localtime().tm_zone)
Where and why are you using this?
In protocol class we do:
self._timezone: ZoneInfo = get_localzone()
get_localzone() from tzlocal already returns a ZoneInfo
instance.
We don't use the time module.
Maybe you are referring to your own code.
Guess it's all working as it is.
Thanks
from python-o365.
@alejcas apologies for lack of clarity.
We already dropped support for pytz. Are you using it?
tzlocal.get_localzone
is still using pytz
under the hood:
import pytz_deprecation_shim as pds
...
def get_localzone():
"""Returns the zoneinfo-based tzinfo object that matches the Windows-configured timezone."""
global _cache_tz
if _cache_tz is None:
_cache_tz = pds.timezone(get_localzone_name())
if not utils._tz_name_from_env():
# If the timezone does NOT come from a TZ environment variable,
# verify that it's correct. If it's from the environment,
# we accept it, this is so you can run tests with different timezones.
utils.assert_tz_offset(_cache_tz)
return _cache_tz
So you might have dropped pytz
everywhere else in your code, but you are using it through tzlocal.get_localzone
The fix is in the connection.patch
patchfile attached to this comment
Here again -> connection.patch
We don't use the time module. Maybe you are referring to your own code.
I know that you are not, I am suggesting you do instead of tzlocal
Guess it's all working as it is.
Unfortunately it is not working as it is.
from python-o365.
Ah I see! As I am testing from git, I didn't update the deps.
Let me test again
from python-o365.
Awesome!
Tested with
• Updating tzdata (2023.4 -> 2024.1)
• Updating tzlocal (5.0 -> 5.2)
And it all works like a charm. Thanks ;)
from python-o365.
Related Issues (20)
- Cannot save Planner TaskDetails without checklist
- How to determine if a message is forward or reply? HOT 2
- Reading content of .msg and .eml type attachments is not possible HOT 3
- Upload session Error HOT 2
- Problem with authentication: Error AADSTS50194 HOT 1
- Cookie based auth HOT 1
- What does the msgraph-sdk-python mean for the future of this project? HOT 3
- Client Error: 404 Client Error: Not Found for url: when switching between sharepoint and onedrive resources HOT 5
- I can't use refresh token in airflow environment HOT 3
- ZoneInfo object has no attribute Zone exception HOT 3
- Reach to the file name by the path HOT 1
- 'zoneinfo.ZoneInfo' object has no attribute 'zone' HOT 1
- "Protocol not provided to Api Component" when copying files from a shared OneDrive HOT 3
- requirements.txt not consisting with setup.py dependency versions HOT 1
- TimeZone Handling HOT 8
- No email rule creation
- O365.utils.utils.Query.any does not support negate() and does not follow the group? HOT 4
- No auth token found. Authentication Flow needed HOT 1
- Inconsistent behavior of `attachment.attachment_type` in legacy vs new Outlook HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-o365.