Problem with urllib

2

I'm trying to solve python challege # 4 but when I run my possible solution I get an error. My solution is as follows:

import urllib, re


pattern = re.compile("and the next nothing is \d")
text = "and the next nothing is 12345"
nothing = int(text[-5:])
check = re.search(pattern, text)

while check:  # main loop
    url = urllib.urlopen("www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}".format(nothing))
    text = url.read()
    nothing = int(text[-5:])
    check = re.search(pattern, text)

print text

And when I run I get this error:


Traceback (most recent call last):
  File "Python_Challenge_4.py", line 12, in 
    url = urllib.urlopen("www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}".format(nothing))
  File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 463, in open_file
    return self.open_local_file(url)
  File "/usr/lib/python2.7/urllib.py", line 477, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: 'www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'

Note : I do not want a solution for python challenge 4, I just want to know the cause of this error.

    
asked by anonymous 07.10.2015 / 01:02

1 answer

2

If the urlopen method does not identify the scheme of the URL ( link , link , file: , etc) such as opening a local file. See official documentation :

  

Open a network object denoted by a URL for reading. If the URL does   not have a scheme identifier, or if it has file: as its scheme   identifier, this opens a local file

    
07.10.2015 / 02:24