# events and pickle library

**URL:** <https://discourse.obspy.org/t/events-and-pickle-library/786>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [July 3, 2018, 3:23pm UTC](https://discourse.obspy.org/t/events-and-pickle-library/786 "2018-07-03T15:23:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolaos\_Triantafyll](https://discourse.obspy.org/user_avatar/discourse.obspy.org/nikolaos_triantafyll/32/264_2.png) [@Nikolaos\_Triantafyll](https://discourse.obspy.org/u/Nikolaos_Triantafyll)\
**Post date:** [July 3, 2018, 3:23pm UTC](https://discourse.obspy.org/t/events-and-pickle-library/786/1 "2018-07-03T15:23:09Z")

</div>

Hi everyone,

Something weird is happening when using the pickle library.

I use a python code to get the event list:  
# get the events  
catalog=fdsn.get\_events(starttime=starttime\_check,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endtime=endtime\_check,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minmagnitude=cfg.mag\_thres,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;magnitudetype="MLh",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;includeallorigins=False,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;includeallmagnitudes=False,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;includearrivals=True,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;orderby="time-asc",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;limit=cfg.event\_limit)

# and save them into a file for later use  
with open('catalog','w') as f: # tried with wb also  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pickle.dump(catalog,f)

From another script:  
with open('catalog','r') as f:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catalog=pickle.load(f)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print catalog

When I run both scripts sequentially, I have no problem. Even if I run, later, the second one script repetitively.

However, if, for instance, I reboot my computer and run only the second script, I get the error (at the print statement):

AttributeError: 'UTCDateTime' object has no attribute '\_UTCDateTime\_\_ns'

Any ideas? What could be the cause of "destroying" the data?

Thanks,  
Nikos

---

<div class="post-metadata">

**Author:** ![LionKrischer](https://discourse.obspy.org/user_avatar/discourse.obspy.org/lionkrischer/32/219_2.png) [@LionKrischer](https://discourse.obspy.org/u/LionKrischer)\
**Post date:** [July 4, 2018, 11:50am UTC](https://discourse.obspy.org/t/events-and-pickle-library/786/2 "2018-07-04T11:50:48Z")

</div>

Hi Nikos,

are you using the same ObsPy + Python version every time? Pickling is  
really fragile when the internal structure of objects is changed. We do  
make an effort to support cross-version pickling (of course this can  
only work in a forward compatible way - i.e. pickled objects from an  
older ObsPy version should be readable on newer ObsPy versions) and if  
we missed something here please open an issue on github with a small but  
complete reproducible example.

Some general advice: Best try to avoid pickling data if you can, mainly  
for compatibility reasons. Your specific example would work by just doing

> > > cat.write("catalog.xml", format="quakeml")

Which you can then read in subsequent scripts. This works as long as the  
chosen data format can represent everything in the objects. The  
`client.get_events(...)` method alternatively also supports a `filename`  
argument which can be used to download the catalog directly to a file.

Cheers,

Lion
