Python urllib.urlopen IOError

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-04-20T03:19:20Z Indexed on 2010/04/20 3:23 UTC
Read the original article Hit count: 528

Filed under:
|

So I have the following lines of code in a function

sock = urllib.urlopen(url)
html = sock.read()
sock.close()

and they work fine when I call the function by hand. However, when I call the function in a loop (using the same urls as earlier) I get the following error:

> Traceback (most recent call last):
  File "./headlines.py", line 256, in <module>
    main(argv[1:])
  File "./headlines.py", line 37, in main
    write_articles(headline, output_folder + "articles_" + term +"/")
  File "./headlines.py", line 232, in write_articles
    print get_blogs(headline, 5)
  File "/Users/michaelnussbaum08/Documents/College/Sophmore_Year/Quarter_2/Innovation/Headlines/_code/get_content.py", line 41, in get_blogs
    sock = urllib.urlopen(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 203, in open
    return getattr(self, name)(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib.py", line 314, in open_http
    if not host: raise IOError, ('http error', 'no host given')
IOError: [Errno http error] no host given

Any ideas?

© Stack Overflow or respective owner

Related posts about python

Related posts about urllib