I thought I was calling this correctly but obviously not. Can someone tell me what I am doing wrong?
import urllib.request
class testURLopener(urllib.request.FancyURLopener):
def __init__(self, user, passwd):
self.__user = user
self.__passwd = passwd
urllib.FancyURLopener.__init__(self)
if __name__ == '__main__' :
opener = testURLopener()
opener.setpasswd("user", "password")
web_byte = opener.open('https://www.test.com')
print(web_byte.getcode() )
Here is the problem:
opener = testURLopener()
as you set a condition ion your init to get the username and password. You may change the arguments to named instead of positional and set the default values with the following code (you would need the correct namespace for FancyURLopener):
def __init__(self, user="", passwd=""):
self.__user = user
self.__passwd = passwd
urllib.request.FancyURLopener.__init__(self)