Python Post nie działa

0

Witam,

mam taki kod do pobierania wartosci z czujnika a pozniej wysylam go postem na serwer.

(temperature,pressure)=readBmp180()
  print("Temperature : {0} C".format(temperature))
  print("Pressure    : {0} mbar".format(pressure))



data = {
  "cisnienie": pressure,
  "temperatura" : temperature
}

req = urllib2.Request('serwer')
req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req, json.dumps(data))


Ale mam jakis problem ze zmienna przechowujaca cisnienie i temperature nie jest dostepna wewnatrz
data= {}

Jak to naprawic?

0

Musisz utworzyć słownik i dodać te dane do niego:

(temperature,pressure)=readBmp180()
  print("Temperature : {0} C".format(temperature))
  print("Pressure    : {0} mbar".format(pressure))

data = {}
data["pressure"] = pressure
data["temperature"] = temperature

req = urllib2.Request('serwer')
req.add_header('Content-Type', 'application/json')

response = urllib2.urlopen(req, json.dumps(data))

1 użytkowników online, w tym zalogowanych: 0, gości: 1