HTTP REST Sensor Upload

Medium Python Protocols
Solve this problem

Write a Python script to upload sensor measurements to a REST endpoint using HTTP POST. Handle JSON serialization and connection errors.

Constraints

  • Use requests library.
  • Endpoint: http://example.com/data.
  • JSON format: {"id":X,"value":Y}.
  • Timeout of 5 seconds.
  • Retry once on failure.
Starter codePython
1import requests2# TODO