urllib2.urlopen("localhost"): ERROR

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
INFACT
User
Beiträge: 385
Registriert: Freitag 5. Dezember 2008, 16:08

Hi,

urllib2.urlopen weigert sich, meinen localhorst anzusprechen.

Code: Alles auswählen

>>> urlopen("127.0.0.1")
Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    urlopen("127.0.0.1")
  File "C:\Python26\lib\urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python26\lib\urllib2.py", line 381, in open
    protocol = req.get_type()
  File "C:\Python26\lib\urllib2.py", line 242, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: 127.0.0.1
Was kann ich da machen?
Gibts eine andere möglichkeit oder einen workaround?
[b][i]ein kleines game für die die lust haben http://konaminut.mybrute.com[/i][/b]
;-)
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Schon mal versucht dass Protokoll davor zu setzen? Schließlich ist ``127.0.0.1`` ja nichtmal eine URL, da wärs ja etwas dreist zu erwarten dass urllib sowas kann.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
INFACT
User
Beiträge: 385
Registriert: Freitag 5. Dezember 2008, 16:08

grrr...

Danke!
Das klappt, aber wenn ich jetzt noch ein port dazuhaben will

Code: Alles auswählen

urlopen("http://localhost:8461")
Bekomme ich diese Meldung:

Code: Alles auswählen

Traceback (most recent call last):
  File "<pyshell#48>", line 1, in <module>
    urlopen("http://localhost:8461")
  File "C:\Python26\lib\urllib2.py", line 124, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python26\lib\urllib2.py", line 395, in open
    response = meth(req, response)
  File "C:\Python26\lib\urllib2.py", line 508, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python26\lib\urllib2.py", line 427, in error
    result = self._call_chain(*args)
  File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
    result = func(*args)
  File "C:\Python26\lib\urllib2.py", line 603, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Python26\lib\urllib2.py", line 395, in open
    response = meth(req, response)
  File "C:\Python26\lib\urllib2.py", line 508, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python26\lib\urllib2.py", line 427, in error
    result = self._call_chain(*args)
  File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
    result = func(*args)
  File "C:\Python26\lib\urllib2.py", line 603, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "C:\Python26\lib\urllib2.py", line 395, in open
    response = meth(req, response)
  File "C:\Python26\lib\urllib2.py", line 508, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python26\lib\urllib2.py", line 433, in error
    return self._call_chain(*args)
  File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
    result = func(*args)
  File "C:\Python26\lib\urllib2.py", line 516, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 440: 
[b][i]ein kleines game für die die lust haben http://konaminut.mybrute.com[/i][/b]
;-)
Benutzeravatar
Defnull
User
Beiträge: 778
Registriert: Donnerstag 18. Juni 2009, 22:09
Wohnort: Göttingen
Kontaktdaten:

Auch das ist noch keine URL. Versuch "http://localhost:8461/"

PS: Da sieht man mal, wie schädlich Fehler tolerante Software (Browser) is, wenn es um die Verbreitung von Standards und Konventionen geht ;)
Bottle: Micro Web Framework + Development Blog
INFACT
User
Beiträge: 385
Registriert: Freitag 5. Dezember 2008, 16:08

Macht keinen unterschied
Defnull hat geschrieben:Auch das ist noch keine URL. Versuch "http://localhost:8461/"

PS: Da sieht man mal, wie schädlich Fehler tolerante Software (Browser) is, wenn es um die Verbreitung von Standards und Konventionen geht ;)
Ich gebe immer nur einzelne Wörter in den Browser: "python forum", "python clientform download" etc.
[b][i]ein kleines game für die die lust haben http://konaminut.mybrute.com[/i][/b]
;-)
ms4py
User
Beiträge: 1178
Registriert: Montag 19. Januar 2009, 09:37

Also bei mir funktioniert das:

Code: Alles auswählen

>>> urllib2.urlopen('http://localhost:8000/')
<addinfourl at 44852088 whose fp = <socket._fileobject object at 0x02AC3330>>
Liegt vermutlich an deinem Webserver! Was steckt denn dahinter?
nemomuk
User
Beiträge: 862
Registriert: Dienstag 6. November 2007, 21:49

localhost != 127.0.0.1 außer in der hosts-Datei angegeben.
apollo13
User
Beiträge: 827
Registriert: Samstag 5. Februar 2005, 17:53

SchneiderWeisse hat geschrieben:localhost != 127.0.0.1 außer in der hosts-Datei angegeben.
selbst dann macht es je nach anwendung einen unterschied…
Zuletzt geändert von apollo13 am Samstag 7. November 2009, 12:42, insgesamt 1-mal geändert.
nemomuk
User
Beiträge: 862
Registriert: Dienstag 6. November 2007, 21:49

apollo13 hat geschrieben:
SchneiderWeisse hat geschrieben:localhost != 127.0.0.1 außer in der hosts-Datei angegeben.
selbst dann macht es ja nach anwendung einen unterschied…
Wie meinen? Verstehe irgendwie den Satz nicht... ja=je?
apollo13
User
Beiträge: 827
Registriert: Samstag 5. Februar 2005, 17:53

Sry, sollte natürlich je heißen, habs mal ausgebessert…
Antworten