proxy_support = urllib.request.ProxyHandler({'http': '127.0.0.1:8118'})
opener = urllib.request.build_opener(proxy_support)

def newId():
    conn = TorCtl.connect(controlAddr='127.0.0.1', controlPort=9051,
        passphrase='your_password')
conn.send_signal('NEWNYM')
for i in range(0, 10):
    print('case ' + str(i + 1))
newId()
proxy_support = urllib.request.ProxyHandler({'http': '127.0.0.1:8118'})
urllib.request.install_opener(opener)
print(urllib.request.urlopen('http://www.ifconfig.me/ip').read())
How to change Tor identity in Python?