Q: python3 does not change the tor IP I try to change tor ip in python3 but it doesn't always work the same
can you recommend me an effective method with python3?
import time
import socket
import socks
import requests

from urllib.request import urlopen
from stem import Signal
from stem.control import Controller


controller = Controller.from_port(port=9051)

def connectTor():
    socket.socket = None
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050, True)
    socket.socket = socks.socksocket

def renewTor():
    controller.authenticate("xxxxxxx")
    controller.signal(Signal.NEWNYM)
     

def showIP():
    ip =requests.get('https://httpbin.org/ip',
        proxies = {
            'http': 'socks5://127.0.0.1:9050',
            'https': 'socks5://127.0.0.1:9050'
        }).text
    print(ip)

for i in range(5):
    renewTor()
    connectTor()
    showIP()
    time.sleep(30)



response of change IP
{
"origin": "185.220.131.43"
}
{
"origin": "185.220.131.43"
}
{
"origin": "185.220.131.43"
}
{
"origin": "185.220.131.43"
}
{
"origin": "185.220.131.43"
}
