Re: exception in urllib2

Discussion in 'Python' started by 7stud, Feb 1, 2009.

  1. 7stud

    7stud Guest

    On Feb 1, 3:34 am, asit <> wrote:
    > I hv been developing a link scanner. Here the objective is to
    > recursively scan a particular web site.
    >
    > During this, my script methttp://images.google.co.in/imghp?hl=en&tab=wi
    > and passed it to the scan function, whose body is like this..
    >
    > def scan(site):
    >


    So you have this:

    site=http://images.google.co.in/imghp?hl=en&tab=wi

    ??



    >     log=open(logfile,'a')
    >     log.write(site + "\n")
    >     site = "http://" + site.lower()
    >


    So now:

    site = "http://" + "http://images.google.co.in/imghp?hl=en&tab=wi"

    Hmmm...let's see what happens when I run the following program:


    import urllib

    site = "http://" + "http://images.google.co.in/imghp?hl=en&tab=wi"
    html = urllib.urlopen(site)

    --output:--
    Traceback (most recent call last):
    File "6test.py", line 4, in ?
    html = urllib.urlopen(site)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/urllib.py", line 82, in urlopen
    return opener.open(url)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/urllib.py", line 190, in open
    return getattr(self, name)(url)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/urllib.py", line 303, in open_http
    h = httplib.HTTP(host)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/httplib.py", line 1097, in __init__
    self._setup(self._connection_class(host, port, strict))
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/httplib.py", line 586, in __init__
    self._set_hostport(host, port)
    File "/Library/Frameworks/Python.framework/Versions/2.4//lib/
    python2.4/httplib.py", line 598, in _set_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
    httplib.InvalidURL: nonnumeric port: ''
    7stud, Feb 1, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,516
  2. jeff
    Replies:
    3
    Views:
    1,675
    Scott
    Jun 26, 2003
  3. Kerri
    Replies:
    2
    Views:
    12,992
    Kevin Spencer
    Oct 27, 2003
  4. Josef Cihal
    Replies:
    0
    Views:
    726
    Josef Cihal
    Sep 5, 2005
  5. ak
    Replies:
    7
    Views:
    5,418
Loading...

Share This Page