I'm trying to get a new IP in a tor session using stem and the following function which is heavily 'inspired' by this answer:
def get_new_IP(): socket.socket = old_socket with Controller.from_port(port=SOCKS_PORT) as controller: controller.authenticate() controller.signal(Signal.NEWNYM) socket.socket = socks.socksocket
However I get the error 'IncorrectSocketType: unable to use the control socket' raised by
controller.authenticate() which leaves me a little lost since there is no password or anything specified and the initial connection I set up works too.
I have also tried to add
'CookieAuthentication': str(1), as suggested here, to the config settings when starting the tor process, however that didn't work either.
How come that the initial connection works and why can't I get authenticated when I try to reconnect?