subclass urllib2

Alex Willmer alex at moreati.org.uk
Mon Feb 28 17:40:25 EST 2011


On Feb 28, 6:53 pm, monkeys paw <mon... at joemoney.net> wrote:
> I'm trying to subclass urllib2 in order to mask the
> version attribute. Here's what i'm using:
>
> import urllib2
>
> class myURL(urllib2):
>      def __init__(self):
>          urllib2.__init__(self)
>          self.version = 'firefox'
>
> I get this>
> Traceback (most recent call last):
>    File "<interactive input>", line 1, in <module>
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
>
> I don't see where i am supplying 3 arguments. What am i
> missing?

urllib2 is a module, not a class, so you can't subclass it. You could
subclass one of the classes inside urllib2, such as
urllib2.BaseHandler. Whether you want to depends on what your want to
achieve.



More information about the Python-list mailing list