Unindent与任何外部缩进级别都不匹配修复

时间:2018-03-27 19:52:38

标签: python forms

我想制作一个在后台填写抽奖表格的脚本。

我在网上看到了一个脚本,并编辑了我的所有。

现在我发现了一个错误,并且不知道如何修复它,因为我是初学者。

如果有人可以帮助我,那会很酷。

  

文件“main.py”,第58行       test = sesh.post(url,data = data)                                     ^   IndentationError:unindent与任何外部缩进级别都不匹配

脚本:

import requests, time, names, random, json, string
from random import randint, choice
#
sizes = ['EUR 40 | US 7','EUR 40.5 | US 7.5','EUR 41 | US 8','EUR 42 | US 8.5','EUR 42.5 | US 9','EUR 43 | US 9.5','EUR 44 | US 10','EUR 44.5 | US 10,5','EUR 45 | US 11','EUR 45.5 | US 11.5','EUR 46 | US 12','EUR 47 | US 12.5','EUR 47.5 | US 13']
#
def session():
    sesh = requests.session()
    sesh.headers = {
        'Origin':'https://www.sneakerdistrict.com',
        'Referer':'https://www.sneakerdistrict.com/wotherspoon/',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'
    }
    sesh.headers.update()
    return sesh
#
def proxysession(proxy):
    ip,port,username,password = proxy.split(":")
    formattedProxy = (username+':'+password+'@'+ip+':'+port)
    proxies = {'http': 'http://'+formattedProxy}
    proxies = {'https': 'https://'+formattedProxy}
    sesh = requests.Session()
    sesh.proxies = proxies
    sesh.headers = {
        'Origin':'https://www.sneakerdistrict.com',
        'Referer':'https://www.sneakerdistrict.com/wotherspoon/',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'
    }
    sesh.headers.update()
    return sesh
#first,last,email,street,zip,city,country,telephone,size
def post(sesh,url,first,email,street,zip,city,country,telephone,size,delay):
        data = {
            'form_fields[0][name]': 'first_name',
            'form_fields[0][value]': first,
            'form_fields[1][name]': 'last_name',
            'form_fields[1][value]': last,
            'form_fields[2][name]': 'email',
            'form_fields[2][value]': email,
            'form_fields[3][name]': 'street',
            'form_fields[3][value]': street,
            'form_fields[4][name]': 'zip',
            'form_fields[4][value]': zip,
            'form_fields[5][name]': 'city',
            'form_fields[5][value]': city,
            'form_fields[6][name]': 'country',
            'form_fields[6][value]': country,
            'form_fields[7][name]': 'telephone',
            'form_fields[7][value]': telephone,
            'form_fields[8][name]': 'size',
            'form_fields[8][value]': size,

        }
    test = sesh.post(url,data=data)
    if '{"status":"success"}'==test.text:
        print("Entered successfully:")
        signup = first,last,email,street,zip,city,country,telephone,size
        print(signup)
        f = open('entries.txt','a')
        f.write(str(signup)+'\n')
        f.close
    time.sleep(delay)

def main:
    with open('config.json') as json_data_file:
        data = json.load(json_data_file)
        form = data['settings']['form']
        catchalldomain = data['settings']['catchalldomain']
        randomnames = data['settings']['randomnames']
        first = data['settings']['setfirst']
        last = data['settings']['setlast']
        signupdelay = int(data['settings']['signupdelay'])
        randomsizes = data['settings']['randomsizes']
        size = data['settings']['size']
        street = data['settings']['setstreet']
        zip = data['settings']['setzip']
        city = data['settings']['setcity']
        country = data['settings']['country']
        telephone = data['settings']['telephone']
        proxyuse = data['settings']['useproxy']
        proxy = data['settings']['proxy']
#
        if randomnames == 'True':
            first = names.get_first_name(gender='male')
            last = names.get_last_name()
        randomletters = "".join(choice(string.ascii_letters) for x in range(randint(1, 4)))
        username = randomletters+first+randomletters
        email = username+'@'+catchalldomain
        if randomsizes == 'True':
            size = random.choice(sizes)
        if proxyuse == 'True':
                    sesh = proxysession(proxy)
                else:
                    sesh = session()
#
        post(sesh,form,first,last,email,street,zip,city,country,telephone,size,signupdelay)
print("Raffle Bot")

with open('usernames.txt') as f:
    content = f.readlines()
for i in content:
    main(i)

这是config.json:

{
    "settings":{
    "form":"https://www.sneakerdistrict.com/wotherspoon/app/ajax/form-submit.php",
    "catchalldomain":"test@club",
        "randomnames":"False",
        "setfirst":"Test",
    "setlast":"Test",
        "signupdelay":"5",
    "randomsizes":"True",
    "size":"EUR 44 | US 10",
    "setstreet":"Ave",
    "setzip":"607998",
    "setcity":"Dayton",
    "country":"United States",
    "telephone":"154577697",
        "useproxy":"False",
    "proxy":"ip:port:username:password"
    }
}

1 个答案:

答案 0 :(得分:0)

错误暗示您的缩进已关闭。 Python使用空格。例如

def session():
    sesh = requests.session()
    sesh.headers = {
        'Origin':'https://www.sneakerdistrict.com',
        'Referer':'https://www.sneakerdistrict.com/wotherspoon/',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36'
    }

这将是会话功能的适当缩进。只需添加空格,接受的标准是4个空格。