The NEWNYM
signal is not meant for acquiring a new exit node, it merely marks the current circuit as dirty and ensures the new connections will use a new circuit.
From the stem docs:
An important thing to note is that a new circuit does not necessarily mean a new IP address. Paths are randomly selected based on heuristics like speed and stability. There are only so many large exits in the Tor network, so it's not uncommon to reuse an exit you have had previously.
Tor does not have a method for cycling your IP address. This is on purpose, and done for a couple reasons. The first is that this capability is usually requested for not-so-nice reasons such as ban evasion or SEO. Second, repeated circuit creation puts a very high load on the Tor network, so please don't!
Edit. I missed initially you're not using Tor (proxy) when making a request! That's the first part of the problem.
You should first install socks
support for requests
library (pip install requests[socks]
) and then make a request via local Tor proxy, like this:
requests.get('https://httpbin.org/ip',
proxies={'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}).text