2013-07-11 34 views
0

我想使用Python 2.7連接到Tor,但是當我嘗試訪問使用urllib或urllib2的網站時,它保持我的正常IP。 (IM使用維達利亞) (是的,它說Tor運行時) 這裏是我的代碼:Python沒有連接到Tor(TorCtl)

import urllib 
import TorCtl 
password = "" ## your tor password 
conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase= password) ## Connect to tor 
ip = urllib.urlopen('http://hypersource.net78.net/autos/ip.php').read() ## Get IP address 
print "ip address: " + str(ip) 
TorCtl.Connection.send_signal(conn, "NEWNYM") ## change IP 
ip = urllib.urlopen('http://hypersource.net78.net/autos/ip.php').read() ## Get IP address 
print "ip address: " + str(ip) 

如何獲得它連接?

回答

0

TorCtl控制Tor;您仍然需要配置urllib以使用代理。 Read the documentation;您可能更願意僅爲您的情況設置超過[, proxies]的環境變量。

下面介紹如何使用proxies,雖然:

proxies = {'http': 'http://localhost:9050/'} 
ip = urllib.urlopen('http://hypersource.net78.net/autos/ip.php', proxies=proxies).read() 

如果您使用的任何其他協議(例如,HTTPS),指定在proxies了。

+0

tor不是一個http代理。 (這就是我得到的錯誤) – JD3

+0

它仍然給我我在TOR之前的知識產權。 – JD3