Stem 未在 Python 中生成新的 IP 地址
Stem is not generating new IP address in Python
为什么 Signal.NEWNYM
没有生成新的 IP 地址?
from stem import Signal
from stem.control import Controller
import requests
with Controller.from_port(port=9051) as controller:
print('Ready')
controller.authenticate(password='872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C')
print("Success!")
controller.signal(Signal.NEWNYM)
print("New Tor connection processed")
print(requests.get('http://icanhazip.com').content)
NEWNYM
信号并不意味着获取新的出口节点,它只是将当前电路标记为脏并确保新连接将使用新电路。
来自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!
编辑。我最初想念您在发出请求时没有使用 Tor(代理)!这是问题的第一部分。
您应该首先安装 socks
对 requests
库 (pip install requests[socks]
) 的支持,然后通过本地 Tor 代理发出请求,如下所示:
requests.get('https://httpbin.org/ip',
proxies={'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}).text
当你发出请求时你得到了相同的 IP 或者第一次 IP 没有改变?
如果请求的 IP 相同:您应该让脚本休眠 30 秒,然后才能正常工作。
我遇到了同样的问题,睡眠解决了。
def renew_connection():
with Controller.from_port(port=9051) as controller:
controller.authenticate(password="YourPass")
controller.signal(Signal.NEWNYM)
time.sleep(30)
还要确保密码和端口正确!
为什么 Signal.NEWNYM
没有生成新的 IP 地址?
from stem import Signal
from stem.control import Controller
import requests
with Controller.from_port(port=9051) as controller:
print('Ready')
controller.authenticate(password='872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C')
print("Success!")
controller.signal(Signal.NEWNYM)
print("New Tor connection processed")
print(requests.get('http://icanhazip.com').content)
NEWNYM
信号并不意味着获取新的出口节点,它只是将当前电路标记为脏并确保新连接将使用新电路。
来自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!
编辑。我最初想念您在发出请求时没有使用 Tor(代理)!这是问题的第一部分。
您应该首先安装 socks
对 requests
库 (pip install requests[socks]
) 的支持,然后通过本地 Tor 代理发出请求,如下所示:
requests.get('https://httpbin.org/ip',
proxies={'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}).text
当你发出请求时你得到了相同的 IP 或者第一次 IP 没有改变?
如果请求的 IP 相同:您应该让脚本休眠 30 秒,然后才能正常工作。
我遇到了同样的问题,睡眠解决了。
def renew_connection():
with Controller.from_port(port=9051) as controller:
controller.authenticate(password="YourPass")
controller.signal(Signal.NEWNYM)
time.sleep(30)
还要确保密码和端口正确!