I've got a function to create accout on some website. It makes it automatically with solving captcha.
Here's my function:
def create_account():
global login
global password
global email
print('# REJESTROWANIE NOWEGO KONTA')
s=requests.Session()
headers = {
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'en-US,en;q=0.8',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
}
s.headers.update(headers)
r=s.get(REGISTER_URL)
soup=BeautifulSoup(r.content, "html.parser")
captcha_img=soup.find("img",{"alt":"captcha"})['src']
nazwa = basename(captcha_img)
capublic = str(os.path.splitext(nazwa)[0])
with open('/root/environments/captcha_img/'+nazwa,"wb") as f:
f.write(requests.get('https://www.mywebsite.net/'+captcha_img).content)
captcha_text = ''
try:
captcha_text = captcha('captcha_img/'+nazwa)
filelist = [ f for f in os.listdir('/root/environments/captcha_img/') if f.endswith(".png") ]
for f in filelist:
os.remove(os.path.join('/root/environments/captcha_img/', f))
except:
print('> nieznany typ captcha')
print('> ponawiam')
text = ''
create_account()
data={
"jscheck": '1',
"login": login,
"pass": password,
"pass2":password,
"email": email,
"cacheck":captcha_text,
"capublic":capublic,
'button_submit': 'Sign+Up+(Free)',
}
r=s.post(REGISTER_URL,headers=headers,data=data)
text = str(r.content)
koniec = 'nie'
if "Your registration was successful" in text:
print('# ZAREJESTROWANO')
print('> login: '+login+', hasło: '+password+', email: '+email)
text = ''
koniec = 'tak'
return
elif "The supplied Captcha is wrong." in text and koniec != 'tak':
print('# BŁĘDNE CAPTCHA')
print('> ponawiam')
text = ''
create_account()
elif "Please fill out both Passwordfields." in text and koniec != 'tak':
print('# NIE WPISANO HASŁA')
print('> ponawiam')
text = ''
create_account()
elif "The supplied Passwords do not match." in text and koniec != 'tak':
print('# HASŁA NIE SĄ TAKIE SAME')
print('> ponawiam')
text = ''
create_account()
elif "Please enter your Username." in text and koniec != 'tak':
print('# NIE WPISANO LOGINU')
print('> ponawiam')
text = ''
create_account()
elif "The Username is already in use." in text and koniec != 'tak':
print('# LOGIN ZAJĘTY')
print('> generuję nowy login')
login = get_uname(5, 10, False)
print('> ponawiam')
text = ''
create_account()
elif "The supplied E-Mail is already in use." in text and koniec != 'tak':
print('# ADRES EMAIL ZAJĘTY')
print('> pobieram nowy adres e-mail')
email = get_email()
print('> ponawiam')
text = ''
create_account()
else:
print('# INNY NIEZNANY BŁĄD')
print('> generuję nowe dane logowania')
login = get_uname(5, 10, False)
password = password = get_password(8)
email = get_email()
print('> ponawiam')
text = ''
create_account()
Sometimes there is an error with solving captcha. There are two errors: when the captcha is wrong or there is unknown captcha type. In both cases I'm running my function again.
When one of this two error appears there is a bug, like in this example:
As You can see, first there was an error Invalid captcha type (nieznany typ captcha) then the function runs again and succesfully created account (ZAREJESTROWANO) and the function should stop. In my code:
if "Your registration was successful" in text:
print('# ZAREJESTROWANO')
print('> login: '+login+', hasło: '+password+', email: '+email)
text = ''
koniec = 'tak'
return
But as You can see on the image (from console) it runs again (BŁĘDNE CAPTCHA).
When there is no error captcha and account is created succesfully everything is ok and the function stop.
I've tried clearing 'text' variable and even add 'koniec' variable but it doesnt solve the problem. Any ideas?
