Hy! Ich habe versucht, eine Webseite zu öffnen, die normalerweise im Browser geöffnet wird, aber Python schwört nur und will nicht arbeiten.Erneut urllib.error.HTTPError: HTTP-Fehler 400: Ungültige Anforderung
import urllib.request, urllib.error
f = urllib.request.urlopen('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphire')
Und eine andere Art und Weise
import urllib.request, urllib.error
opener=urllib.request.build_opener()
f=opener.open('http://www.booking.com/reviewlist.html?cc1=tr;pagename=sapphi
re')
Beide Optionen eine Art von Fehler geben:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\urllib\request.py", line 461, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 493, in error
result = self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 676, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python34\lib\urllib\request.py", line 461, in open
response = meth(req, response)
File "C:\Python34\lib\urllib\request.py", line 571, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python34\lib\urllib\request.py", line 499, in error
return self._call_chain(*args)
File "C:\Python34\lib\urllib\request.py", line 433, in _call_chain
result = func(*args)
File "C:\Python34\lib\urllib\request.py", line 579, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
Irgendwelche Ideen?
Danke, nur habe ich 'von urllib Import FancyURLopener' zu 'von urllib.request Import FancyURLopener' geändert (war Fehler). Und am Ende habe ich den nächsten Fehler (nach dem Ausführen von '>>> page.read()'): ValueError: Lesen der geschlossenen Datei. – Wanu
Also änderte ich Version = 'Mein neuer User-Agent' zu Version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; es; rv: 1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'. Und der Fehler ist verschwunden! Sehr großer Dank! Ich habe lange nach einer Lösung für dieses Problem gesucht, du hast mir sehr geholfen! – Wanu