M
M
my_drone2017-10-07 04:53:38
Python
my_drone, 2017-10-07 04:53:38

How to make Python code work after catching an error but with new values ​​in a variable?

The essence of the question in # comments to the code

import requests
import urllib
from random import choice
from colorama import Fore, Back, Style

url = "http://3g2upl4pq6kufc4m.onion"  # контрольный адрес для проверки работоспособности (код 200)

def ururu():                                               # генерирует рандомный URL
     digits = "abcdefghijklmnopqrstuvwxyz234567"

     adr = "http://" + "".join([choice(digits) for _ in range(16)]) + '.onion'


     return adr


def getdata(adr):

    try:
            print(Fore.GREEN +"I will try => " '%s' %(adr))
            proxies = {'http': 'socks5h://127.0.0.1:9050','https': 'socks5h://127.0.0.1:9050'}
            data = requests.get(adr, proxies=proxies)
            t = data.status_code == requests.codes.ok
            print("Site data " '%s' % (data))
            print("Response " '%s' %(t))

    except requests.exceptions.InvalidURL:
            print("InvalidURL")
    except requests.ConnectionError:     # но как скормить переменной новый URL после отлова ошибки?()
            print("ConnectionError")          # при каждом неверном адресе будет ошибка.Как перебрать Все url? 
            return data

I understand that searching through all the domains of the Tor network is too long a process ..
But this task has been haunting me for a week now. =(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Weridy, 2017-10-07
@my_drone

What prevents a function from calling itself in an instance with a "different" parameter

A
Astrohas, 2017-10-07
@Astrohas

Wrap in a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question