airqus airqus - 1 year ago 173
Python Question

Instancemethod object is not iterable (AirPi) (Python)

I got ERROR:Exception during output: 'instancemethod' object is not iterable when debugging this AirPi code from

This suppose to upload my sensor data to the Ubidots server.

*I'd put my correct token and variable ID inside the configuration file for this AirPi.

requiredSpecificParams = ["token"]
optionalSpecificParams = ["showcost",

def __init__(self, config):
super(Ubidots, self).__init__(config)
self.token = self.params["token"]
if "showcost" in self.params:
self.showcost = self.params["showcost"]
self.showcost = False
self.ubivariables = {}
for key, value in self.params.iteritems():
if key[:3] == "ID-":
if value:
self.ubivariables[key[3:]] = value

def output_data(self, datapoints, dummy):
"""Output data.
Output data in the format stipulated by the plugin. Calibration
is carried out first if required.
Because this particular plugin (ubidots) does not show time, the
third argument (normally called 'sampletime') is called 'dummy'
to facilitate compliance with pylint.
self: self.
datapoints: A dict containing the data to be output.
dummy: datetime representing the time the sample was taken.
boolean True if data successfully output to Ubidots; False if
if self.params["calibration"]:
datapoints =
payload = []
for point in datapoints:
for ubivariablename, ubivariableid in self.ubivariables.iteritems():
if point["sensor"] == ubivariablename:
if point["value"] is not None:
thisvalue = {}
thisvalue["variable"] = ubivariableid
thisvalue["value"] = point["value"]
headers = {'Accept': 'application/json; indent=4', 'Content-Type': 'application/json', 'X-Auth-Token': self.token}
url = ""
req = None
cost = 0
req =, data=json.dumps(payload), headers=headers)
except Exception, e:
print("ERROR: Failed to contact the Ubidots service.")
print("ERROR: " + str(e))
return False
for response in req.json:
if response["status_code"] is not 201:
print("ERROR: Ubidots responded with an error for one of the values.")
return False
cost += 1
if self.showcost:
print("Ubidots upload cost " + str(cost) + " dots.")
return True

Answer Source
for response in req.json:

According to the documentation, json is a method and must be called, so this should be:

for response in req.json():

In the future it is helpful to include just as much of your code as is necessary to reproduce the problem, and to include the complete error message with traceback.