8

I don't understand how it works. I have function log_in with two arguments user and password. And have list with all my users and passwords. So, when I using p.map(log_in, list), it's means that list will iterate and "unpack". Where ['user','bitnami'], ['user1', '12345'] etc will be these arguments log_in(user, password). Yes?

def log_in(user, password): payload = wrap_creds_in_xml(username=user, password=password) response = requests.post(TARGET_URL, payload) if __name__ == '__main__': TARGET_URL = 'http://192.168.1.6/wp-login.php' list = [['user', 'bitnami'], ['user1', '12345'], ['user2', '54321'], ['user3', 'qwerty']] p = Pool(5) p.map(log_in, list) 

And I have error

TypeError: main() missing 1 required positional argument: 'password'

1
  • The error message suggests this isn't the case... Commented Oct 16, 2017 at 15:09

1 Answer 1

13

The problem is that log_in is a function that takes two arguments, but your code passes just a single argument to that function: a list with two elements. Try Pool.starmap instead of Pool.map:

p.starmap(log_in, list) 

From the documentation of Pool.starmap():

Like map() except that the elements of the iterable are expected to be iterables that are unpacked as arguments.

Hence an iterable of [(1,2), (3, 4)] results in [func(1,2), func(3,4)].

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

1 Comment

While this works for some cases, it's unfortunate that Pool.istarmap and Pool.istarmap_unordered don't exist.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.