首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python脚本-帐户生成器

Python脚本-帐户生成器
EN

Stack Overflow用户
提问于 2018-06-13 05:52:05
回答 1查看 4.7K关注 0票数 2

我最近才开始学习python,我试着为一个随机商店写了一个帐户生成器,只是为了学习,我有几个问题。

这是我的代码:

import requests
import random
from random import getrandbits
import time

session = requests.session()

url = 'https://chmielna20.pl/en/register'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'}

name = 'John' #enter your name
surname = 'Doe' #enter your surname
email = 'test+{}@gmail.com'.format(getrandbits(40)) #enter your email, dont     change anything after '+'
password = 'Testing1234' #enter your password, minimum 8 characters

times = int(input("[" + (time.strftime("%H:%M:%S") + "]" + " - Enter the number of account(s) you would like to create: ")))

text_file = open("chmielna accounts.txt", "w")


def create_account():

print("[" + (time.strftime("%H:%M:%S")) + "]" + " - SUBMITTING INFO.....")
global session
global email

    payload = {
        "Name": name,
        "surname": surname,
        "email": email,
        "password": password,
        "zapoznalem": "on"
}

response = session.post(url, data = payload, headers = headers)

def write():
text_file.write(email + ":" + password + "\n")

if "Success" in response.text:
    print("[" + (time.strftime("%H:%M:%S")) + "]" +" - SUCCESSFULLY CREATED     ACCOUNT "+email+":"+password)
    write()
else:
    print("[" + (time.strftime("%H:%M:%S")) + "]" +" - ERROR COULD NOT CREATE "+email+":"+password)

for i in range (times):
create_account()

所以第一个问题是为什么我得到错误‘未使用的变量’有效负载‘’(在定义的create_account中)和‘未定义的变量’有效负载‘’(作为响应)。我在def create_account中定义了有效负载。

第二个问题是在https://chmielna20.pl/en/register上,你必须勾选"Zapoznałam/em sięz Regulaminem sklepu internetowego akceptujęjego postanowienia“-我如何在python中做到这一点?

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2018-06-13 05:55:51

问题:函数内部的缩进不正确或不一致。

错误来自response = session.post(url, data = payload, headers = headers)线路。

使用这个并调整你的代码:

import requests
import random
from random import getrandbits
import time

session = requests.session()

url = 'https://chmielna20.pl/en/register'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'}

name = 'John' #enter your name
surname = 'Doe' #enter your surname
email = 'test+{}@gmail.com'.format(getrandbits(40)) #enter your email, dont     change anything after '+'
password = 'Testing1234' #enter your password, minimum 8 characters

times = int(input("[" + (time.strftime("%H:%M:%S") + "]" + " - Enter the number of account(s) you would like to create: ")))
text_file = open("chmielna accounts.txt", "w")

def create_account():
    print("[" + (time.strftime("%H:%M:%S")) + "]" + " - SUBMITTING INFO.....")
    global session
    global email
    payload = {
        "Name": name,
        "surname": surname,
        "email": email,
        "password": password,
        "zapoznalem": "on"
    }

def write():
    text_file.write(email + ":" + password + "\n")
    if "Success" in response.text:
        print("[" + (time.strftime("%H:%M:%S")) + "]" +" - SUCCESSFULLY CREATED     ACCOUNT "+email+":"+password)
        write()
    else:
        print("[" + (time.strftime("%H:%M:%S")) + "]" +" - ERROR COULD NOT CREATE "+email+":"+password)

for i in range (times):
    create_account()

结果:

[00:33:04] - Enter the number of account(s) you would like to create: 5
[00:33:05] - SUBMITTING INFO.....
[00:33:05] - SUBMITTING INFO.....
[00:33:05] - SUBMITTING INFO.....
[00:33:05] - SUBMITTING INFO.....
[00:33:05] - SUBMITTING INFO.....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50826346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档