I have the following python code that works well:
try:
with urlopen("http://my.domain.com/get.php?id=" + id) as response:
print("Has content" if response.read(1) else "Empty - no content")
except:
print("URL Error has occurred")
But I am trying to change the if else statement within the try to something like this: so that I can run extra code rather than just print a message
try:
with urlopen("http://my.domain.com/get.php?id=" + id) as response:
if response.read(1):
print("Has content")
else:
print("Empty - no content")
except:
print("URL Error has occurred")
But the above is not working, giving an error related to indent
Any ideas what's wrong?
You can put the exception into a variable and print that too
If you indenting looks like the original question, then that may be your problem - mixing tabs with spaces