jwoglom / tconnectsync

Syncs data from Tandem Source (formerly t:connect) to Nightscout for the t:slim X2 and Mobi insulin pumps
MIT License
112 stars 61 forks source link

500 - Error: Cannot parse 2024-06-13+08:49:09.971622 00:00 as a valid ISO-8601 date #93

Open rstutsman opened 3 months ago

rstutsman commented 3 months ago

It looks like Tandem's API might have changed recently (7.17.2.3) and broken things?

I haven't dug deeper into this yet, but it looks like perhaps the date stamps passed to their server need to be adjusted a bit.

$ tconnectsync --features {BASAL,BOLUS}
2024-06-14 08:49:09 INFO     Enabled features: BASAL, BOLUS
Processing data between 2024-06-13 08:49:09.971622 and 2024-06-14 08:49:09.971622 
2024-06-14 08:49:09 INFO     Downloading t:connect ControlIQ data
2024-06-14 08:49:09 INFO     Logging in to ControlIQApi...
2024-06-14 08:49:10 INFO     Reported tconnect software version: t:connect 7.17.2.3
2024-06-14 08:49:10 WARNING  Newer API version than last confirmed working. Saw t:connect 7.17.2.3 and expected t:connect 7.17.1.2
2024-06-14 08:49:10 WARNING  If you experience any issues, please report them to https://github.com/jwoglom/tconnectsync
2024-06-14 08:49:12 INFO     Logged in to ControlIQApi successfully (expiration: 2024-06-14T22:49:10.721Z, in 7 hours, 59 minutes)
2024-06-14 08:49:12 INFO     Downloading t:connect therapy_events
2024-06-14 08:49:13 WARNING  No last CGM reading is able to be determined from CIQ
2024-06-14 08:49:13 WARNING  Downloading t:connect CSV data
2024-06-14 08:49:13 WARNING  Falling back on WS2 CSV data source because BOLUS is an enabled feature and CIQ bolus data was empty!!
2024-06-14 08:49:13 WARNING  <!!> The WS2 data source is unreliable and may prevent timely synchronization
2024-06-14 08:49:15 WARNING  No last CGM reading is able to be determined from CSV
2024-06-14 08:49:16 WARNING  last_uploaded_entry with t_to_space: Nightscout last_uploaded_entry 500 response: <html>
  <head>
    <meta charset='utf-8'> 
    <title>Error: Cannot parse 2024-06-13+08:49:09.971622 00:00 as a valid ISO-8601 date</title>
    <style>* {
  margin: 0;
  padding: 0;
  outline: 0;
}

body {
  padding: 80px 100px;
  font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
  background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9));
  background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9);
  background-repeat: no-repeat;
  color: #555;
  -webkit-font-smoothing: antialiased;
}
h1, h2 {
  font-size: 22px;
  color: #343434;
}
h1 em, h2 em {
  padding: 0 5px;
  font-weight: normal;
}
h1 {
  font-size: 60px;
}
h2 {
  margin-top: 10px;
}
ul li {
  list-style: none;
}
#stacktrace {
  margin-left: 60px;
}
</style>
  </head>
  <body>
    <div id="wrapper">
      <h1>Connect</h1>
      <h2><em>500</em> Error: Cannot parse 2024-06-13+08:49:09.971622 00:00 as a valid ISO-8601 date</h2>
      <ul id="stacktrace"><li> &nbsp; &nbsp;at /app/lib/server/query.js:71:17</li><li> &nbsp; &nbsp;at Array.forEach (&lt;anonymous&gt;)</li><li> &nbsp; &nbsp;at enforceDateFilter (/app/lib/server/query.js:62:28)</li><li> &nbsp; &nbsp;at create (/app/lib/server/query.js:120:5)</li><li> &nbsp; &nbsp;at query_for (/app/lib/server/treatments.js:121:12)</li><li> &nbsp; &nbsp;at Function.list (/app/lib/server/treatments.js:115:13)</li><li> &nbsp; &nbsp;at /app/lib/api/treatments/index.js:100:22</li><li> &nbsp; &nbsp;at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)</li><li> &nbsp; &nbsp;at next (/app/node_modules/express/lib/router/route.js:137:13)</li><li> &nbsp; &nbsp;at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)</li></ul>
    </div>
  </body>
</html>
 (HTTP 500)
2024-06-14 08:49:16 INFO     Last Nightscout basal upload: None
2024-06-14 08:49:16 INFO     finalized bolusEvents: []
2024-06-14 08:49:16 WARNING  last_uploaded_entry with t_to_space: Nightscout last_uploaded_entry 500 response: <html>
  <head>
    <meta charset='utf-8'> 
    <title>Error: Cannot parse 2024-06-13+08:49:09.971622 00:00 as a valid ISO-8601 date</title>
    <style>* {
  margin: 0;
  padding: 0;
  outline: 0;
}

body {
  padding: 80px 100px;
  font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
  background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9));
  background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9);
  background-repeat: no-repeat;
  color: #555;
  -webkit-font-smoothing: antialiased;
}
h1, h2 {
  font-size: 22px;
  color: #343434;
}
h1 em, h2 em {
  padding: 0 5px;
  font-weight: normal;
}
h1 {
  font-size: 60px;
}
h2 {
  margin-top: 10px;
}
ul li {
  list-style: none;
}
#stacktrace {
  margin-left: 60px;
}
</style>
  </head>
  <body>
    <div id="wrapper">
      <h1>Connect</h1>
      <h2><em>500</em> Error: Cannot parse 2024-06-13+08:49:09.971622 00:00 as a valid ISO-8601 date</h2>
      <ul id="stacktrace"><li> &nbsp; &nbsp;at /app/lib/server/query.js:71:17</li><li> &nbsp; &nbsp;at Array.forEach (&lt;anonymous&gt;)</li><li> &nbsp; &nbsp;at enforceDateFilter (/app/lib/server/query.js:62:28)</li><li> &nbsp; &nbsp;at create (/app/lib/server/query.js:120:5)</li><li> &nbsp; &nbsp;at query_for (/app/lib/server/treatments.js:121:12)</li><li> &nbsp; &nbsp;at Function.list (/app/lib/server/treatments.js:115:13)</li><li> &nbsp; &nbsp;at /app/lib/api/treatments/index.js:100:22</li><li> &nbsp; &nbsp;at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)</li><li> &nbsp; &nbsp;at next (/app/node_modules/express/lib/router/route.js:137:13)</li><li> &nbsp; &nbsp;at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)</li></ul>
    </div>
  </body>
</html>
 (HTTP 500)
2024-06-14 08:49:16 INFO     Last Nightscout bolus upload: None
2024-06-14 08:49:16 INFO     Wrote 0 events to Nightscout this process cycle
Added 0 items
jwoglom commented 3 months ago

I think this is a Nightscout time formatting bug, not an issue on Tandem's end. Tconnectsync has logic to try two different timestamp formats when querying Nightscout to work around this, so I think this warning can be ignored in your case.

MatthewMazaika commented 3 months ago

the date/time returned from Nightscout above in the error message is indeed not a valid ISO-8601 datetime

2024-06-13+08:49:09.971622 00:00

according to the spec, the date/time separator should be a T not the + and the timezone should be separated with the + and not a whitespace

2024-06-13T08:49:09.971622+00:00

are we passing the correct date and Nightscout isn't handling it? or are we passing the invalid date and Nightscout is spitting it back verbatim?

jwoglom commented 3 months ago

are we passing the correct date and Nightscout isn't handling it? or are we passing the invalid date and Nightscout is spitting it back verbatim?

Older versions of Nightscout appear to accept writes via the API into Mongo with invalid-formatted dates. (I don't want to throw any blame here, but it might have been an xDrip+ bug?) This means that in some cases the invalid iso-8601 formatted date needs to be sent in order to properly filter dates. Currently, tconnectsync works around this bug by attempting both the "correct" and "incorrect" formats in sequence, and trying the other if such a http 500 occurs.

MatthewMazaika commented 3 months ago

i got this warning, twice, and started to dig in

since the error message is last_uploaded_entry with t_to_space (important part being the t_to_space), it means that we tried to get the data with the correct datetime format but received a 200 response with zero items

i was able to reproduce the empty list with the offending datetime multiple times but eventually nightscout returned the expected result and i could no longer reproduce :thinking: