In your code you have set the query.set_parameter(1, 'sensor_123') value 1 which results in the "Parameter index out of range" error as already mentioned in your error code. Change this value from 1 to 0 and i am sure your issue will be resolved.