-1

When trying to do a try and except part in my code y get this error

local variable 'archivo' referenced before assignment

The code is the following:

archivo=open(os.getcwd()+"/proxies.txt",'r')
def get_data(url):
    try:
        separados=archivo[0].split(":")
        datos_proxy="socks5://"+separados[2]+":"+separados[3]+":"+separados[0]+":"+separados[1]
        proxy={"sock5": datos_proxy}
        r = s.get(url,proxies=proxy)
        r.html.render(sleep=3)
        links=r.html.absolute_links
        for link in links:
            if "0x" in link:
                if "assets" in link:
                    if "matic" not in link:
                        hook.send(link)
    except:
        archivo=archivo[1:]

Gives me the error in the "separadores" variable.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Ismael
  • 99
  • 1
  • 8

1 Answers1

0

You are shadowing the global archivo varible that lies outside of the get_data function.

Either open the file in the function or write global archivo before the try statement.

See here Global Variables w3s

sbaeurle
  • 1
  • 1