The problem is that get vars userd to pass json arguments are always strings.
On Jul 21, 2:38 pm, Michael Ellis <michael.f.el...@gmail.com> wrote: > In a data acquisition system, I need to handle reports for sensor > channels that may not have anything connected to them. The relevant > fields in my table definition look like: > > Field('f_ch1_value_double', type = 'double', default = None, > label = T("CH1")), > Field('f_ch2_value_double', type = 'double', default = None, > label = T("CH2")), > Field('f_ch3_value_double', type = 'double', default = None, > label = T("CH3")), > Field('f_ch4_value_double', type = 'double', default = None, > label = T("CH4")), > Field('f_ch5_value_double', type = 'double', default = None, > label = T("CH5")), > Field('f_ch6_value_double', type = 'double', default = None, > label = T("CH6")), > > and I have a function that starts like this: > > @service.json > def v2_data_insert(timestamp, sensorid, > ch1=None, ch2=None, ch3=None, ch4=None, ch5=None, > ch6=None, > flowrate=None, flowtemp=None, erate=None, > chargev=None, battv=None, sensorv=None): > > db.t_v2_data[0] = dict(f_timestamp_datetime = timestamp, > f_sensor_reference = sensorid, > f_ch1_value_double = ch1, > f_ch2_value_double = ch2, > f_ch3_value_double = ch3, > f_ch4_value_double = ch4, > f_ch5_value_double = ch5, > f_ch6_value_double = ch6, > f_flow_rate_double = flowrate, > f_flow_temp_double = flowtemp, > f_energy_rate_double = erate, > f_battery_charger_double = chargev, > f_battery_volts_double = battv, > f_sensor_volts_double = sensorv) > > Passing None to any of the channel arguments, e.g. ch1 = None, is > raising > > ValueError: could not convert string to float: None > > on the insert call even though null is allowed by the field > definition. I suspect this must be an issue with the way > urllib.urlencode() the dictionary containing the channel values before > the data is posted to my controller. > > The process that sends the data is doing the following: > > encodeddata = urllib.urlencode(data) > response = urllib2.urlopen(server + url, encodeddata) > > where data is the dictionary that maps to the keyword arguments of > v2_data_insert(). > > I can hack around this issue by testing for 'None' as a string value > in the controller, but I'd be grateful for a more elegant soution. > > Thanks, > Mike