can you fix syntax errors in this code

import os
import random
import string
from rich.console import Console
from rich.prompt import IntPrompt
from playwright.sync_api import sync_playwright
from captcha_solver.solvers.twocaptcha import CaptchaSolver

console = Console()


def generate_password(length=20):
alphabet = string.ascii_letters + string.digits + string.punctuation
return ‘’.join(random.choice(alphabet) for _ in range(length))


def generate_nickname():
# Generates a random nickname by combining a word from the file with a random number
try:
with open(‘nicknames.txt’, ‘r’) as file:
words = [line.strip() for line in file.readlines()]
return random.choice(words) + str(random.randint(10000, 999999))
except FileNotFoundError:
console.log(’[bold red]Error:[/] nicknames.txt file not found!‘)
console.print(’[bold]Press enter to exit…[/]‘)
console.input()
exit()


def clear():
# Clears the console screen and adds the name at the beginning
os.system(‘cls’ if os.name == ‘nt’ else ‘clear’)
console.rule(’[bold red]Roblox Account Generator[/]‘)


def registration():
with sync_playwright() as pw:
nickname = generate_nickname()
password = generate_password()
browser = pw.firefox.launch(headless=False) # * Don’t try to use chromium browsers because they got detected by roblox as bot.
context = browser.new_context()
page = context.new_page()
page.set_viewport_size({“width”: 640, “height”: 480})
page.route(‘https://apis.roblox.com/universal-app-configuration/v1/behaviors/cookie-policy/content’, lambda route: route.abort()) # Blocks cookies banner
page.goto(‘https://www.roblox.com’)
page.locator(’//[@id=“MonthDropdown”]‘).select_option(‘January’)
page.locator(’//[@id=“DayDropdown”]‘).select_option(‘01’)
page.locator(’//[@id=“YearDropdown”]‘).select_option(‘1999’)

while True:
# Checks username valid
with page.expect_response(‘https://auth.roblox.com/v1/usernames/validate’) as username_validate:
page.locator(’//[@id=“signup-username”]‘).fill(nickname)
if username_validate.value.json().get(‘code’) == 0:
break
else:
nickname = generate_nickname()

page.locator(’//[@id=“signup-password”]‘).fill(password)
page.locator(’//[@id=“MaleButton”]‘).click()

with page.expect_response(‘https://auth.roblox.com/v2/signup’) as signup_validate:
page.click(’//[@id=“signup-button”]‘, timeout=0)

if signup_validate.value.status == 429:
browser.close()
console.log(’[bold red]Error:[/] too many requests! Try to change your IP (you can use VPN, preferably paid)‘)
console.print(’[bold]Press enter to continue…[/]‘)
console.input()
return None
else:
with page.expect_target_changed() as target_info:
pass

if page.url == ‘https://www.roblox.com/home?nu=true’:
with open(‘cookies.txt’, ‘a’) as file:
cookies = context.cookies()
roblosecurity_cookie = next((cookie for cookie in cookies if cookie[‘name’] == ‘.ROBLOSECURITY’),None) # Finds .ROBLOSECURITY cookies
if roblosecurity_cookie:
roblos_data_value = roblosecurity_cookie[‘value’]
file.write(f’{roblos_data_value}\n’)

with open(‘accounts.txt’, ‘a’) as file:
file.write(f’{nickname}:{password}\n’)
console.log(‘[bold green]Account generated successfully[/]’, ‘:white_check_mark:’)
else:
# Solve funcaptcha
solver = CaptchaSolver(‘YOUR_API_KEY’)
while True:
# Get the challenge URL and the session ID
challenge_url = page.locator(‘//[@id=“FunCaptcha”]/@data-payload-url’)[0]
session_id = page.locator('//[@id=“FunCaptcha”]/@data-session-id’)[0]

# Solve the challenge using 2captcha
captcha_response = solver.solve_captcha(challenge_url)
if not captcha_response.get(‘code’):
# Get the s, sig, and api_server keys from the 2captcha API response
s = captcha_response[‘solution’][‘s’]
sig = captcha_response[‘solution’][‘sig’]
api_server = captcha_response[‘api_server’]

# Pass the s, sig, and api_server keys to the page and submit the form
page.set_extra_headers({‘x-fcapi-session-id’: session_id})
page.set_extra_headers({‘x-fcapi-s-token’: s})
page.set_extra_headers({‘x-fcapi-sig’: sig})
page.route('https://client-api.arkoselabs.com/fc/gt2/public_key/’, lambda route: route.abort())
page.click(‘//*[@id=“signup-button”]’, timeout=0)
break
else:
console.log(f’[bold red]Error:[/] {captcha_response.get(“message”)}‘)
nickname = generate_nickname()
browser.close()
console.log(’[bold green]Account generated successfully[/]', ‘:white_check_mark:’)
return None


def main():
try:
clear()
amount = IntPrompt.ask(‘Enter how many accounts to generate’)
clear()
for _ in range(amount):
with console.status(‘Generating…’, spinner=‘line’):
registration()
except BaseException:
pass

if name == ‘main’:
main()