I would like to get the data to Excel worksheet. The problem is when I run the whole code I receive an error but when I run it separately no error it works.
Here is what I want;
from xlwings import Workbook, Sheet, Range, Chart
import requests
import jsonpayload_city = {'cityId':3969, 'cmd':'districts'}
url = "https://www.garantimortgage.com/apps/Socket/Webservice.ashx"
r_city = requests.post(url, data=payload_city)data_city = json.loads(r_city.text) #json to python data structure conversion
wb = Workbook()
dict = data_city[:] #translation in to dictionary
for i in list(range(len(dict))):print data_city[i]["DistrictName"]payload_district = {'cityId':data_city[i]["CityId"], 'lbDistricts':data_city[i]["DistrictCode"], 'criter':149,'startdate':'2003-01','cmd':'result','areaCode':data_city[i]["AreaWideCode"]}r_district = requests.post(url, data=payload_district)data = json.loads(r_district.text)data = map(dict.values, data[u'output'][u'resultset'][u'record'][u'data']) #---->NOT OK.for row in data:Range("A1").value = zip(*data)
But when I run this as;
from xlwings import Workbook, Sheet, Range, Chart
import requests
import jsonpayload = {'cityId':3969, 'lbDistricts':599, 'criter':149,'startdate':'2003-01','cmd':'result','areaCode':18439}
url = "https://www.garantimortgage.com/apps/Socket/Webservice.ashx"
r = requests.post(url, data=payload)wb = Workbook()
#wb = Workbook.caller()
data = json.loads(r.text)
data = map(dict.values, data[u'output'][u'resultset'][u'record'][u'data'])
for row in data:Range("A1").value = zip(*data)
It works. Could you please tell me where my mistake is? Thank you.