2

I have a set of scrapers written in python that I'm trying to host on Heroku. I've pushed the repo to heroku, and it will begin to run, but quits with an error I never encountered in my local environment.

when I call p = Legislator(name=name, district=district) where both name and district are strings, I get TypeError: __init__() takes at least 3 arguments (2 given)

both Legislator and Person are included in packages my script is dependent on, both of which are specified in requirements.txt could this have something to do with virtualenv?

here is the constructor for Legislator:

    def __init__(self, name, post_id, party=None, chamber=None, **kwargs):
       super(Legislator, self).__init__(name, **kwargs)
       self.post_id = post_id
       self.party = party
       self.chamber = chamber
       self._contact_details = []

and the constructor for Person

   def __init__(self, name, **kwargs):
       super(Person, self).__init__()
       self.name = name
       self.biography = None
       self.summary = None
       self.birth_date = None
       self.death_date = None
       self.image = None
       self.gender = None
       self.links = []
       self.other_names = []
       self.extras = {}
       self._related = []
       self.contact_details = []

       for k, v in kwargs.items():
           setattr(self, k, v)
6
  • 1
    I'm not very familiar with python 3 inheritance, so apologies if this is a ignorant question, but why are you calling super(Person, self).__init__() inside the constructor for Person? It looks like you're trying to make Person inherit from Person. And if there is a good reason to do that, shouldn't it be super(Person, self).__init__(name)? Commented Aug 9, 2013 at 18:11
  • 1
    that confuses me a bit too to be honest, that part isn't my code, its from the package I'm using. Person comes from github.com/opencivicdata/larvae/blob/master/larvae/person.py and Legislator comes from github.com/opencivicdata/pupa/blob/master/pupa/scrape/… Commented Aug 9, 2013 at 18:19
  • 2
    Waitaminute - if Legislator takes arguments self, name, post_id, party=None, chamber=None, **kwargs, and you gave it <Legislator instance>, name=name, district=district, then you haven't given it a post_id argument, have you? Isn't that the 3rd missing argument? I'm not sure how you managed to avoid this error in your local environment... Commented Aug 9, 2013 at 18:36
  • aha! you're right! turns out post_id was added two days ago and I didn't update the dependencies on my local environment. Thank you!! Commented Aug 9, 2013 at 18:41
  • 1
    No prob - I missed it the first time around :) Commented Aug 9, 2013 at 18:45

1 Answer 1

2

Legislator takes arguments:

self, name, post_id, party=None, chamber=None, and **kwargs

and you gave it

<Legislator instance>, name=name, and district=district,

then you haven't given it a post_id argument - that's the 3rd missing argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.