Skip to content

Instantly share code, notes, and snippets.

@joeyhagedorn
Last active April 11, 2020 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyhagedorn/d8642521524addddb9a8305f9ea72051 to your computer and use it in GitHub Desktop.
Save joeyhagedorn/d8642521524addddb9a8305f9ea72051 to your computer and use it in GitHub Desktop.
Simple write_api usage showing errors including missing samples (0, 9, 27, 30, 36, etc)
client = InfluxDBClient(url=url, token=token)
write_api = client.write_api(write_options=WriteOptions(batch_size=8, flush_interval=8, jitter_interval=0, retry_interval=1000))
for i in range(50):
valOne = float(i)
valTwo = float(i)+0.5
pointOne = Point("Pressure").tag("sensor", "sensor1").field("PSI", valOne).time(time=datetime.utcnow())
pointTwo = Point("Pressure").tag("sensor", "sensor2").field("PSI", valTwo).time(time=datetime.utcnow())
write_api.write(bucket, orgID, [pointOne, pointTwo])
print ("PSI Readings: (%f, %f)" %(valOne, valTwo))
time.sleep(0.5)
PSI Readings: (0.000000, 0.500000)
The batch item wasn't processed successfully because: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 11 Apr 2020 23:46:17 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '54', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'x-platform-error-code': 'invalid'})
HTTP response body: {"code":"invalid","message":"writing requires points"}
PSI Readings: (1.000000, 1.500000)
PSI Readings: (2.000000, 2.500000)
PSI Readings: (3.000000, 3.500000)
PSI Readings: (4.000000, 4.500000)
PSI Readings: (5.000000, 5.500000)
PSI Readings: (6.000000, 6.500000)
PSI Readings: (7.000000, 7.500000)
PSI Readings: (8.000000, 8.500000)
PSI Readings: (9.000000, 9.500000)
PSI Readings: (10.000000, 10.500000)
PSI Readings: (11.000000, 11.500000)
PSI Readings: (12.000000, 12.500000)
PSI Readings: (13.000000, 13.500000)
PSI Readings: (14.000000, 14.500000)
PSI Readings: (15.000000, 15.500000)
PSI Readings: (16.000000, 16.500000)
PSI Readings: (17.000000, 17.500000)
PSI Readings: (18.000000, 18.500000)
PSI Readings: (19.000000, 19.500000)
PSI Readings: (20.000000, 20.500000)
PSI Readings: (21.000000, 21.500000)
PSI Readings: (22.000000, 22.500000)
PSI Readings: (23.000000, 23.500000)
PSI Readings: (24.000000, 24.500000)
PSI Readings: (25.000000, 25.500000)
PSI Readings: (26.000000, 26.500000)
PSI Readings: (27.000000, 27.500000)
The batch item wasn't processed successfully because: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 11 Apr 2020 23:46:31 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '54', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'x-platform-error-code': 'invalid'})
HTTP response body: {"code":"invalid","message":"writing requires points"}
PSI Readings: (28.000000, 28.500000)
PSI Readings: (29.000000, 29.500000)
PSI Readings: (30.000000, 30.500000)
The batch item wasn't processed successfully because: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 11 Apr 2020 23:46:32 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '54', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'x-platform-error-code': 'invalid'})
HTTP response body: {"code":"invalid","message":"writing requires points"}
PSI Readings: (31.000000, 31.500000)
PSI Readings: (32.000000, 32.500000)
PSI Readings: (33.000000, 33.500000)
PSI Readings: (34.000000, 34.500000)
PSI Readings: (35.000000, 35.500000)
PSI Readings: (36.000000, 36.500000)
The batch item wasn't processed successfully because: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 11 Apr 2020 23:46:35 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '54', 'Connection': 'keep-alive', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'x-platform-error-code': 'invalid'})
HTTP response body: {"code":"invalid","message":"writing requires points"}
PSI Readings: (37.000000, 37.500000)
PSI Readings: (38.000000, 38.500000)
PSI Readings: (39.000000, 39.500000)
PSI Readings: (40.000000, 40.500000)
PSI Readings: (41.000000, 41.500000)
PSI Readings: (42.000000, 42.500000)
PSI Readings: (43.000000, 43.500000)
PSI Readings: (44.000000, 44.500000)
PSI Readings: (45.000000, 45.500000)
PSI Readings: (46.000000, 46.500000)
PSI Readings: (47.000000, 47.500000)
PSI Readings: (48.000000, 48.500000)
PSI Readings: (49.000000, 49.500000)
#group false false true true false false true true true
#datatype string long dateTime:RFC3339 dateTime:RFC3339 dateTime:RFC3339 double string string string
#default _result
result table _start _stop _time _value _field _measurement sensor
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:17.952364032Z 1.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:18.458908928Z 2.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:18.984709888Z 3.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:19.510621184Z 4.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:20.022403072Z 5.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:20.533586944Z 6.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:21.044142848Z 7.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:21.56784896Z 8.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:22.586477056Z 10.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:23.101715968Z 11.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:23.61876608Z 12.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:24.12749696Z 13.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:24.638663168Z 14.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:25.157382912Z 15.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:25.673851904Z 16.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:26.182388992Z 17.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:26.699084032Z 18.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:27.20589312Z 19.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:27.719582208Z 20.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:28.23190912Z 21.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:28.736633088Z 22.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:29.241991168Z 23.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:29.754712064Z 24.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:30.264292096Z 25.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:30.775152896Z 26.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:31.817344Z 28.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:32.329676032Z 29.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:33.357181184Z 31.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:33.872374016Z 32.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:34.385756928Z 33.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:34.900322048Z 34.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:35.416265984Z 35.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:36.452274176Z 37.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:36.963139072Z 38.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:37.473568Z 39.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:37.990947072Z 40.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:38.510927872Z 41.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:39.018148864Z 42.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:39.52776192Z 43.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:40.049752064Z 44.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:40.568747008Z 45.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:41.078850048Z 46.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:41.589206016Z 47.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:42.100792832Z 48.5 PSI Pressure sensor2
0 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:42.628862976Z 49.5 PSI Pressure sensor2
#group false false true true false false true true true
#datatype string long dateTime:RFC3339 dateTime:RFC3339 dateTime:RFC3339 double string string string
#default _result
result table _start _stop _time _value _field _measurement sensor
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:17.952316928Z 1 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:18.458828032Z 2 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:18.984646144Z 3 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:19.510548224Z 4 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:20.022349056Z 5 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:20.533516032Z 6 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:21.044070912Z 7 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:21.567787776Z 8 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:22.586402048Z 10 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:23.101639936Z 11 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:23.618695936Z 12 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:24.127415808Z 13 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:24.638601984Z 14 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:25.15730816Z 15 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:25.67380096Z 16 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:26.182332928Z 17 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:26.699026944Z 18 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:27.205820928Z 19 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:27.719508992Z 20 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:28.231867904Z 21 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:28.736592128Z 22 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:29.241929984Z 23 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:29.754651136Z 24 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:30.264211968Z 25 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:30.775081984Z 26 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:31.817284096Z 28 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:32.32962304Z 29 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:33.357106944Z 31 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:33.872296192Z 32 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:34.385680896Z 33 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:34.900246016Z 34 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:35.416205824Z 35 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:36.452215808Z 37 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:36.963069952Z 38 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:37.47352192Z 39 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:37.990904064Z 40 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:38.51087104Z 41 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:39.01809408Z 42 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:39.52770304Z 43 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:40.049668096Z 44 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:40.568674048Z 45 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:41.07879296Z 46 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:41.589132032Z 47 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:42.100719872Z 48 PSI Pressure sensor1
1 2020-04-11T23:42:04.766438638Z 2020-04-11T23:47:04.766438638Z 2020-04-11T23:46:42.628802048Z 49 PSI Pressure sensor1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment