config.socks_endpoint fails when having multiple endpoints
See original GitHub issueHi,
I have been running some simple examples for performing http requests with txtorcon and treq. Even a simple script has errors:
from twisted.internet.task import react
from twisted.internet.defer import ensureDeferred
from twisted.internet.endpoints import TCP4ClientEndpoint
import treq
import txtorcon
async def main(reactor):
tor = await txtorcon.connect(
reactor,
control_endpoint=TCP4ClientEndpoint(reactor, '127.0.0.1', 9051),
password_function=lambda: 'mypass',
)
state = await tor.create_state()
circ = await state.build_circuit()
await circ.when_built()
print(' path: {}'.format(' -> '.join([r.ip for r in circ.path])))
config = await tor.get_config()
resp = await treq.get(
'http://httpbin.org/ip',
agent=circ.web_agent(reactor, config.socks_endpoint(reactor)),
timeout=3,
)
data = await resp.text()
print(data)
out = await state.close_circuit(circ)
@react
def _main(reactor):
return ensureDeferred(main(reactor))
But I get a builtins.AttributeError: 'list' object has no attribute 'startswith'
error.
I have noticed that the issue is because of the config.socks_endpoint(reactor)
. When calling that method, I have self.SocksPort = _ListWrapper[['unix:/run/tor/socks WorldWritable', '9050']]
, which is a list of list. Then, when that method is calling the _endpoint_from_socksport_line
things get even worst, as we are passing a list instead of a socket endpoint.
I have tor service listening on port 9050 (and 9051 for control), and also in unix socket /run/tor/socks
(and /run/tor/control
for control).
A super ugly and nonsense patch to fix it is just to go to _endpoint_from_socksport_line
method and force the socks_config
argument (which is a list) to get the second value (which is ‘9050’). If I try the first value (which is ‘unix:/run/tor/socks WorldWritable’), I will get an error too.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (8 by maintainers)
Top GitHub Comments
I have installed latest Tor from their official repository. My OS is Ubuntu 20.04 LTS.
https://2019.www.torproject.org/docs/debian.html.en
Latest Tor version there is 0.4.3.5-1~focal+1 (amd64)
So, I think the value should be
_ListWrapper['unix:... WorldWritable', '9050']
… that is, a single list with two strings (what you’ve got looks like a single list with a single entry: another list).