-1

I want to make a script that fills out raffle forms in the background.

I saw a script online and edited to my belongs.

Now I found an error and don't know how to fix it because im a beginner.

It would be cool if some one can help me.

File "main.py", line 58 test = sesh.post(url,data=data) ^ IndentationError: unindent does not match any outer indentation level

Script:

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)

This is the 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"
    }
}
Max F
  • 61
  • 1
  • 4
  • There are indentation errors in the code you posted before the parser gets to that line. Please ensure you post an accurate representation of what you're looking at locally. Just post the whole code block in one go, highlight it all and press ctrl + k, or click the `{}` button in the editor. – roganjosh Mar 27 '18 at 19:54
  • 1
    Ok i changed it – Max F Mar 27 '18 at 20:07
  • Much better, and now your error is clear. Hold your mouse cursor to the left of the beginning `t` in `test = sesh.post(url,data=data)` and scroll up. The level of indentation matches nothing above it within that function. As the answer posted states, it's recommended that you use 4 spaces for indentation for each level (editors will usually convert tabs to spaces for you to stop you having to keep hammering the spacebar). – roganjosh Mar 27 '18 at 20:09
  • thanks alot! But now im getting Whats wrong with that? – Max F Mar 27 '18 at 20:18
  • `def main:` should be `def main():` (just because the function doesn't take any arguments, doesn't mean you can define it without `()`. But that's it, please don't expect us to debug code for you if you immediately hit problems; take time to look through what might be causing the error step-by-step. Happy coding. – roganjosh Mar 27 '18 at 20:20
  • Ok Thank you again – Max F Mar 27 '18 at 20:23

1 Answers1

0

Your indentation is off as the error implies. Python uses whitespace. For example

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'
    }

that would be the appropriate indent for the session function. Just add spaces, the accepted standard is 4 spaces.

krflol
  • 1,105
  • 7
  • 12