当我使用 ldap3 查询 Active Directory 时,结果的时区默认情况下似乎是 UTC。
在文档中我找到了一个时区模块,但我不知道如何正确使用它,所以我的日期时间结果的偏移量为-2。
https://ldap3.readthedocs.io/source/ldap3.core.html#ldap3.core.timezone.OffsetTzInfo
from ldap3 import Tls, Server, Connection, ALL, SUBTREE, NTLM
from ldap3.core.timezone import OffsetTzInfo
import ldap3
import ssl
server = Server('windc.company.de', use_ssl=True, get_info=ALL, connect_timeout=1),
conn = Connection(server, user=USER, password=PASSWORD, authentication=NTLM, receive_timeout=2)
conn.bind()
Path_Root = "DC=Domain,DC=company,DC=de"
Filter= "(&(objectclass=user)(&(sAMAccountName=someUseName)(!(objectclass=computer))))"
conn.search(search_base=Path_Root, search_filter=Filter, search_scope=SUBTREE, attributes = ["lastLogon"])
据我了解,必须将以下字符串插入到查询中。
tzinfo=OffsetTzInfo(offset=-2, name='abc')