即使我传递了必需的位置参数也缺少1?

问题描述 投票:1回答:1

我遇到了一个问题,即使我通过指定的参数来启动它设法出错的线程,也需要一个必需的'位置参数'

import threading, requests, random, ctypes
from time import sleep
from threading import Thread
from datetime import datetime

cookies = open("cookies.txt").read().splitlines()
ids = open("Scraped Users.txt").read().splitlines()
successful = 0

    class Roblox():
        def __init__(self, cookie):
            self.user_agent = "Roblox/WinInet"
            self.csrf_token = ""
            self.session = requests.Session()
            self.session.cookies[".ROBLOSECURITY"] = cookie

        def send_pm(self, userId):
            req = self.session.post(
                url = "https://privatemessages.roblox.com/v1/messages/send",
                headers = {"User-Agent": self.user_agent, "X-CSRF-TOKEN":     self.csrf_token},
                json = {"subject":'test',"body":'test',"recipientid":userId,"cacheBuster":str(datetime.now())},
            )
            if "X-CSRF-TOKEN" in req.headers:
                self.csrf_token = req.headers["X-CSRF-TOKEN"]
                return self.send_pm(userId)
            return req.json()

    def thread(cookie):
        global successful
        global cookies
        global ids
        while True:
            try:
                ctypes.windll.kernel32.SetConsoleTitleW(f'Message Bot | Cookies: {len(cookies)} | Sent Messages: {successful}')
                chosenId = random.choice(ids)
                session = Roblox(cookie)
                messaging = session.send_pm(chosenId)

            with open("finishedIds.txt") as f:
                        if chosenId in f.read():
                            ids.remove(chosenId)
                            print("User has been already messaged, finding new ID")
                            return thread()

            if messaging["success"] == True:
                    print("Successfully messaged userId:", chosenId)
                    successful = successful + 1
                    ids.remove(chosenId)
                    with open("finishedIds.txt", "a") as f:
                            f.write(chosenId + "\n")
            elif messaging["success"] == False and messaging['message'] == "You're sending too many messages too quickly.":
                    print("Failed to send message due to ratelimit, retrying in 10s")
                    sleep(10)
            else:
                    print("Failed to message, reason: {}".format(messaging['message']))

        except Exception as error:
            print("Error:", error)

for cookie in cookies:
    process = Thread(target=thread, args=(cookie,))
    print("Starting threads..")
    sleep(2)
    process.start()

该函数应该运行在带有要满足该参数的cookie的thread()上-尽管它在几秒钟后开始接收错误,并且如果我只放置一个'cookie'而不是两个,那么它就可以运行'会完美无误地工作]

thread() missing 1 required positional argument: 'cookie'
python python-multithreading
1个回答
0
投票

[我认为您使用多个Cookie进行测试时可能会添加newline,>

1   cookie_1
2   cookie_2
3              # <-- can't have `newline`
© www.soinside.com 2019 - 2024. All rights reserved.