im getting a type error and my class is using self in its function dl()
import urllib
import httplib
import os.path
###SAI22 Library###
def exists(site):
conn = httplib.HTTPConnection(site)
conn.request("HEAD",site)
response = conn.getresponse()
conn.close()
return response.status == 200
class sai_download:
def dl(self,_dir,_url,pck):
if pck == True:
if exists(_url) == True:
urllib.urlretrieve(_url,_dir)
if os.path.isfile(_dir) == True:
print "Download successful"
return True
else:
print "Download failed"
return False
else:
print "Url isnt valid"
return False
elif pck == False:
if exists(_url) == True:
urllib.urlretrieve(_url,_dir)
return True
if os.path.isfile(_dir) == True:
return True
else:
return False
else:
return False
When ran I get the type error but I have self in the class function dl, what I do wrong?
>>> s = sai_download()
>>> s.dl("C:\hh.html","http://stackoverflow.com/questions/82831/check-if-a-file-exists-using-python")
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
s.dl("C:\hh.html","http://stackoverflow.com/questions/82831/check-if-a-file-exists-using-python")
TypeError: dl() takes exactly 4 arguments (3 given)
>>>