Mal als Beispiel:
Code: Alles auswählen
import urllib.request
def DateiDownload(url):
dateiname = url.rsplit('/',1)
dateiname = str(dateiname[1])
webfile = urllib.request.urlopen(url, 'rb')
f = open(dateiname, 'wb')
a = webfile.read()
f.write(a)
webfile.close()
f.close()
print (dateiname, 'heruntergeladen.',sep=' ')
url = "http://www.python-forum.de/styles/PyFo_Classic/imageset/site_logo.gif"
DateiDownload(url)
Fehlermeldungen:
Code: Alles auswählen
Traceback (most recent call last):
File "C:/.../text.py", line 17, in <module>
DateiDownload(url)
File "C:/.../text.py", line 7, in DateiDownload
webfile = urllib.request.urlopen(url, 'rb')
File "C:\...\Python32\lib\urllib\request.py", line 138, in urlopen
return opener.open(url, data, timeout)
File "C:\...\Python32\lib\urllib\request.py", line 367, in open
req = meth(req)
File "C:\...\Python32\lib\urllib\request.py", line 1066, in do_request_
raise TypeError("POST data should be bytes"
TypeError: POST data should be bytes or an iterable of bytes. It cannot be str.
Ich bin aus den Fehlermeldungen nicht schlau geworden. Wie gesagt genau das Skript lief bei mir bereits (sehr gut).