CircuitEvent socks_username and socks_password is always None
Passing a socks user and pass with the request will not lead to these attributes being set, but the stream isolation is triggered.
import io
import pycurl
from stem.process import launch_tor_with_config
from stem.control import Controller, EventType
SOCKS_PORT = 9050
CONTROL_PORT = 9051
def query(url, user=None, passw=None):
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(query.URL, url)
query.setopt(query.PROXY, '127.0.0.1')
query.setopt(query.PROXYPORT, SOCKS_PORT)
query.setopt(query.PROXYTYPE, 7)
query.setopt(query.PROXYUSERNAME, user)
query.setopt(query.PROXYPASSWORD, passw)
query.setopt(query.WRITEFUNCTION, output.write)
query.perform()
return output.getvalue()
def circ_event(circ):
print(circ.socks_username, circ.socks_password)
tor_process = launch_tor_with_config(
config={'SocksPort': str(SOCKS_PORT),
'ControlPort': str(CONTROL_PORT),
'SOCKSListenAddress': '127.0.0.1'})
controller = Controller.from_port(port=CONTROL_PORT)
controller.authenticate()
controller.add_event_listener(circ_event, EventType.CIRC)
query('http://example.com/', user='data', passw='lost')
controller.close()
tor_process.kill()
Output:
None None
None None
None None
None None
None None
None None
None None
None None
None None
None None
Trac:
Username: trodun