I have following code, in which i have to handle exception for 2 statements,
2nd line and 4th line
if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
deviceXML = re.search("LOCATION:(.*.xml)", datagram, flags=re.IGNORECASE).group(1) # this line
root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read())
friendlyName = root.find('.//{}friendlyName'.format(Server.namespace)).text # this line
if not friendlyName in deviceList.keys():
deviceList[friendlyName] = host
self.model.setStringList(deviceList.keys())
How can i use nested try/catch here
I tried following way:
if(re.search("USN:.*MediaRenderer", datagram, flags=re.IGNORECASE)):
try:
deviceXML = re.search("LOCATION:(.*.xml)", datagram, flags=re.IGNORECASE).group(1)
root = ElementTree.fromstring(urllib2.urlopen(XMLLocation).read())
try:
friendlyName = root.find('.//{}friendlyName'.format(Server.namespace)).text
print "\n fname = ", friendlyName
if not friendlyName in deviceList.keys():
deviceList[friendlyName] = host
self.model.setStringList(deviceList.keys())
except:
pass
This is giving me indentation error for except line