Good day! There is the following code:
for i in json_data['data']: if i['user'] == 'user': time = (i['dur']) start_time= (i['start']) task = (i['task']) client = (i['client']) project = (i['project']) description = (i['description']) d = (xtemptime/1000) hours, remainder = divmod(d, 3600) minutes, seconds = divmod(remainder, 60) hh = ("%d" % (hours)) mm = ("%d" % (minutes)) request = u"""<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Insert xmlns="http://tempuri.org/"> <workdate>{start_time}</workdate> <customer>{client}</customer> <project>{project}</project> <workname>{description}</workname> <hours>{hh}</hours> <minutes>{mm}</minutes> <comments></comments> <worktype>1</worktype> </Insert> </soap:Body> </soap:Envelope>""".format(start_time=start_time, client=client, project=project, description=description, hh=hh, mm=mm) encoded_request = request.encode('utf-8') authenticationHeader = { "Host": "host", "Content-Type": "text/xml; charset=UTF-8", "Content-Length": len(encoded_request) } response = requests.post(url="http:url", auth=HttpNtlmAuth('',''), headers = authenticationHeader, data = encoded_request, verify=False) All data is taken from json_data = r.json() which is higher and in general everything is fine with it.
The loop (for i in json_data['data']:) works fine when it receives several entries at the input, but only request = u"""... (last) gets into request = u"""... .
An example of how it looks now (if you arrange print i and print request ):
~]# python test.py (1800000, u'2016-09-10T12:00:00+03:00', None, u'test2', u'test2', u'test2') (24296000, u'2016-09-10T11:35:44+03:00', None, u'test', u'test', u'test') <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Insert xmlns="http://tempuri.org/"> <workdate>2016-09-10T11:35:44+03:00</workdate> <customer>test</customer> <project>test</project> <workname>test</workname> <hours>1</hours> <minutes>1</minutes> <comments></comments> <worktype>1</worktype> </Insert> </soap:Body> </soap:Envelope> ~]# How to make request = u""".. Get all the records going through the for loop, and then requests.post send them? As you can see, what applies to test2 did not fall into the request .
Maybe I generally go in the wrong direction, and it is better to do something else?