简体   繁体   中英

Tor + Urllib2 Python

I am trying to use tor to get a new IP every time I access a website:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, '127.0.0.1', 9151, True)
socket.socket = socks.socksocket
import urllib2
print urllib2.urlopen("http://almien.co.uk/m/tools/net/ip/").read()

I have also tried port 9150, 9050 too.

I keep getting:

socks.ProxyConnectionError: Error connecting to SOCKS4 proxy 127.0.0.1:9151: [Errno 61] Connection refused

Use stem package to interact with Tor. Official site have many tutorials for different cases, for example:

https://stem.torproject.org/tutorials/to_russia_with_love.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM