@@ -139,8 +139,8 @@ def parse_earthquake(feature: dict) -> dict | None:
139139 "magnitude" : float (mag ) if mag is not None else "NaN" ,
140140 "magType" : mag_type or "unknown" ,
141141 "place" : place or "Unknown location" ,
142- "eventTime" : str ( event_time_ms ) ,
143- "updatedTime" : str ( updated_ms ) ,
142+ "eventTime" : event_time_ms ,
143+ "updatedTime" : updated_ms ,
144144 "latitude" : float (lat ),
145145 "longitude" : float (lon ),
146146 "depth_km" : float (depth_km ) if depth_km is not None else 0.0 ,
@@ -204,6 +204,7 @@ def __init__(self):
204204 "OSH_BASE_URL" ,
205205 f"https://{ self .osh_address } /{ self .osh_root } /api" ,
206206 )
207+ self ._coerce_time_to_str = "csapi-go" in self ._base_url
207208 self ._auth = "Basic " + base64 .b64encode (
208209 f"{ self .osh_user } :{ self .osh_pass } " .encode ()).decode ()
209210
@@ -243,6 +244,13 @@ def _post_observation(self, obs: dict):
243244 """POST an observation to the server."""
244245 import ssl
245246
247+ # Go CSAPI server requires Time fields as strings
248+ if self ._coerce_time_to_str :
249+ r = obs .get ("result" , {})
250+ for key in ("eventTime" , "updatedTime" ):
251+ if key in r and not isinstance (r [key ], str ):
252+ r [key ] = str (r [key ])
253+
246254 url = f"{ self ._base_url } /datastreams/{ self ._ds_id } /observations"
247255 body = json .dumps (obs ).encode ()
248256
0 commit comments