Code snippet:
167 def newCustomer(custInputFile): 168 print "adding Customers from " + custInputFile 169 with open(custInputFile, 'rb') as cfile: 170 reader = csv.reader(cfile) 171 rownum = 0 172 for row in reader: 173 #print row 174 if rownum == 0: 175 header = row 176 else: 177 colnum = 0 178 payload = {} 179 for col in row: 180 cname = header[colnum] 181 cval = col 182 payload[cname] = cval 183 colnum += 1 184 Customersurl = url + '/customer/' 185 response = requests.post(Customersurl, data=json.dumps(payload), headers=headers) 186 187 # Check for HTTP codes other than 201 188 if response.status_code != 201: 189 print('Status:', response.status_code, 'Problem with the request. Exiting.') 190 exit() 191 rownum = +1
No comments:
Post a Comment