Hello im having hard time to use the tor stem module, it causes error on the with Controller.from_port(port=9050) as controller:
I tried to check if my i am running on port 9050 using netstats, the service on the tor is already enabled
tcp 0 0 127.0.0.1:9050 0.0.0.0:* LISTEN
Here's my setup
import requests
import socks
import socket
from stem import Signal
from stem.control import Controller
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
session = requests.session()
def renew_tor_ip():
with Controller.from_port(port=9050) as controller:
controller.authenticate(password='malakititeko')
controller.signal(Signal.NEWNYM)
renew_tor_ip()
The traceback error:
SOCKS5Error Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/socks.py in connect(self, dest_pair, catch_errors)
808 negotiate = self._proxy_negotiators[proxy_type]
--> 809 negotiate(self, dest_addr, dest_port)
810 except socket.error as error:
10 frames
SOCKS5Error: 0x01: General SOCKS server failure
During handling of the above exception, another exception occurred:
GeneralProxyError Traceback (most recent call last)
GeneralProxyError: Socket error: 0x01: General SOCKS server failure
During handling of the above exception, another exception occurred:
SocketError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/stem/socket.py in _make_socket(self)
536 return control_socket
537 except socket.error as exc:
--> 538 raise stem.SocketError(exc)
539
540
SocketError: Socket error: 0x01: General SOCKS server failure
Based on you given code change the port to the 9051 and configure the password on the torrc
found on the etc/tor/
uncomment the ControlPort
, password replace that with your own password generated using tor --hash-pssword <your password>
this should work
Try to explore this repo for more infos: