How to get out of a try/except inside a while? [Python]

前端 未结 4 751
野趣味
野趣味 2021-02-14 16:12

I\'m trying this simple code, but the damn break doesn\'t work... what is wrong?

while True:
    for proxy in proxylist:
        try:
            h = urllib.urlo         


        
4条回答
  •  一个人的身影
    2021-02-14 16:55

    You just break out of for loop -- not while loop:

    running = True
    while running:
        for proxy in proxylist:
            try:
                h = urllib.urlopen(website, proxies = {'http': proxy}).readlines()
                print 'worked %s' % proxy
                running = False
            except:
                print 'error %s' % proxy
    print 'done'
    

提交回复
热议问题