3

Estou tentando resolver a python challege #4 mas quando eu executo minha possível solução eu obtenho um erro. A minha solução é a seguinte:

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

e quando executo obtenho esse erro:


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'

Nota: Eu não quero uma solução para a python challenge 4, apenas quero saber a causa desse erro.

1
  • já tentou colocar http no começo da url ? 7/10/2015 às 0:21

1 Resposta 1

4

Caso o método urlopen não identificar o scheme da URL (http:, https:, file:, etc) ele interpreta como a abertura de um arquivo local. Veja na documentação oficial:

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

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .