bac
bac

Reputation: 625

Exception Raising in Urllib2 - Python

I'm trying to use the following code to check whether a given site is online:

url_list = ["www.apple.com", "www.invalidurlname.com"]
for i in url_list:
    try:
        urllib2.urlopen(i, timeout = 1)
    except urllib2.URLError:
        print "fail"
    else:
        print "pass"

It should produce:

pass
fail

However when I run it I get the following error:

  File "scanpb.py", line 7
urllib2.urlopen("http://apple.com", timeout = 1)
      ^
IndentationError: expected an indented block

Where have I gone wrong? Thanks.

Upvotes: -1

Views: 274

Answers (1)

phihag
phihag

Reputation: 287805

You mixed tabs and spaces (displaying tabs as tab and spaces as .:

tab try:
....tab urllib2.urlopen(i, timeout = 1)

Set your editor to either one, and use your editor's replace function to replace all occurences (you can match tabs with \t in regex mode).

Upvotes: 2

Related Questions