I'll start by saying I've never worked with an API before and I'm sure there are more advanced ways of handling my problem but I myself and not that advanced. That being said I'm using MS to build the file framework but I need to account for multiple items to be processed in the same file. The py file I'm building looks like this, as created through my script...
Code: Select all
import httplib, urllib, base64
headers = {
# Request headers
'Authorization': '********',
'EnvironmentCode': '********',
'Ocp-Apim-Subscription-Key': '********',
}
params = urllib.urlencode({
})
try:
conn = httplib.HTTPSConnection('***.**-api.net')
conn = httplib.HTTPSConnection('***.**-api.net')
conn.request("DELETE", "/admin/location/46208?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("Errno {0}] {1}".format(e,errno, e.strerror))
Now I have an excel list of about 1500 id's so my thought is repeat the try statement and exception part of my code, using the id as a variable being read from the excel file for each iteration. The only problem is I don't know how to do this
Can anyone point me in the right direction while I'm banging my head against the wall trying to figure it out for myself? Like, there has to be a way to create a reusable code block or perhaps read from a text file, cut and paste the try statement up until the id, then fill the id with the current value form the current iteration on the excel file, then continue a copy and paste for the remainder of the code. Then repeat that process for however many instances are counted from the excel file. Right? That sounds feasible. Right?
UPDATE 1:
I've split my generated code into three text files, header, try1, and try2, and I'm reading my excel sheet into an array. Now to see if I can figure out the number of elements in my array then structure a loop accordingly... I think.