1

The below code will show the issue with map func as the 3 args to login function very important

import requests
import random
import concurrent.futures

data = open("data.txt","r").read().splitlines()
#loding the username and password
url="example.com/login"
proxy= open("proxy.txt", "r").read().splitlines()
scheme = 'http://'

def login(data ,proxy,scheme):
    #for each row in the data to login with it

    datanow=data.split(":")
    user=datanow[0]
    password=datanow[1]

    prox =random.choice(proxy)
    prox=scheme+prox        

    headers={
    "Accept-Encoding":"gzip, deflate",
    "Content-Length": "159",
    "Connection":"keep-alive",
    "Accept": "application/json",        
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36",
"Content-Type": "application/json",
    }

    data={
    "LOG_USER_IN":"true",
    "user_name": user ,
    "password": password
        }
    proxies = {
                'http': prox
                } 
    r=requests.post(url , timeout=5 , headers = headers,data=data ,proxies=proxies )

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    ### error come here as map take only the second argument as the parameters
    executor.map(login ,data ,proxy,scheme)
    #printing the reaspose
    print(r)

If I use a bad way or the concurrent.futures is not the best way please told me because i am beginner

1
  • You should be able to use 3 arguments in a map call without any problems - what is the error you are getting? – bmshort Jul 8 '20 at 22:00
1
executor.map(lambda p: login(*p) , (data ,proxy, scheme))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.