0
from ldap3 import Server, Connection, ALL
import pickle

server = Server('ipa.demo1.freeipa.org', get_info=ALL)
conn = Connection(server, 'uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org', 'Secret123', auto_bind=True)
entries = conn.extend.standard.paged_search('dc=demo1,dc=freeipa,dc=org', '(objectClass=person)', attributes=['cn', 'givenName', 'createtimestamp'], paged_size=5)

testlist = []

for entry in entries:
    testlist.append(entry)

output = open('data.pkl', 'wb')
pickle.dump(testlist, output)
output.close()

pkl_file = open('data.pkl', 'rb')
test2 = pickle.load(pkl_file)

pkl_file.close()

gives...

C:\Python36\python.exe C:/Users/xxxxx/Dropbox/xxx/Work/Python/CEDAR/ldaptest.py
Traceback (most recent call last):
  File "C:/Users/xxxxx/Dropbox/xxx/Work/Python/CEDAR/ldaptest.py", line 20, in <module>
    test2 = pickle.load(pkl_file)
TypeError: __init__() missing 2 required positional arguments: 'offset' and 'name'

Process finished with exit code 1

this looks to be related to ldap3.core.timezone.py...

the createtimestamp attribute looks to be datetime.datetime(2017, 6, 18, 11, 13, 38, tzinfo=OffsetTzInfo(offset=0, name='UTC'))

unfortunately this is where I don't have a clue what to do next... Is this something that should be addressed before pickling with the datetime object itself?

I'm not able to re-create this with a regular Python datetime object.

dangel
  • 7,238
  • 7
  • 48
  • 74
  • Try to import `tzinfo` in your `__main__` Namespace. If this doesn't help you have to remove `tzinfo` from `createtimestamp` before picking and reassing it after depickelinf. – stovfl Jul 01 '17 at 18:00
  • I believe https://stackoverflow.com/questions/36238351/python-pickle-loads-failed-for-class-instance to be related – dangel Jul 02 '17 at 00:03

0 Answers0