Стектрейс:
D:\tmp\6>python get.py http://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/
Commons-logo.svg/24px-Commons-logo.svg.png
Traceback (most recent call last):
File "get.py", line 41, in <module>
main()
File "get.py", line 37, in main
download_file(arg)
File "get.py", line 13, in download_file
u = urllib2.urlopen(url)
File "c:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "c:\Python27\lib\urllib2.py", line 384, in open
protocol = req.get_type()
File "c:\Python27\lib\urllib2.py", line 245, in get_type
raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: get.py
import urllib2
import sys
import urllib2
def download_file2(url):
print(url)
def download_file(uri):
#url = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/24px-Commons-logo.svg.png"
url = uri
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'w')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += block_sz
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
return 0
def main():
for arg in sys.argv:
download_file(arg)
return 0
if __name__ == "__main__":
main()
download_file(arg) на download_file2
то все ок - аргумент выводится на консоль.
Я хочу написать простую и легковесную замену вгету на питоне, но не могу понять в чем тут ошибка.
Судя по всему в download_file вместо строки приходит что то другое.