0

I want to use a tbselenium package for browser automation but however when I try to run the code I get the following error TBDriverPortError: SOCKS port 9050 is not listening.

following is the code snippet that I have used.

import unittest
from time import sleep
from tbselenium.tbdriver import TorBrowserDriver
import tbselenium.common as cm


class TestSite(unittest.TestCase):
    def setUp(self):
        # Point the path to the tor-browser_en-US directory in your system
        tbpath = r'C:\Users\Sachin\Desktop\Tor Browsernew'
        self.driver = TorBrowserDriver(tbpath, tbb_logfile_path='test.log')
        self.url = "https://check.torproject.org"

    def tearDown(self):
        # We want the browser to close at the end of each test.
        self.driver.close()

    def test_available(self):
        self.driver.load_url(self.url)
        # Find the element for success
        element = self.driver.find_element_by_class_name('on')
        self.assertEqual(str.strip(element.text),
                         "Congratulations. This browser is configured to use Tor.")
        sleep(2)  # So that we can see the page


if __name__ == '__main__':
    unittest.main()

can any one help me solve this error have been struggling for days

codehacker
  • 320
  • 2
  • 3
  • 16

1 Answers1

0

You need to uncomment ControlPort, HashedControlPassword and CookieAuthentication from Torrc file.

you can get torrc from here

then reload tor services.

if you are facing issues post full trackback in your Question

Sangram
  • 354
  • 1
  • 12
  • I am able to connect to tor using ypu method but one issue still persists that i wanted to use the firfox application fromt he tor bundle but this is using normal firfox and due to which i am not able to use the us exit node Though i have mentioned the exit node in torrc – codehacker Jan 22 '20 at 06:55
  • your solution worked like charm but any help on the country exit nodes – codehacker Jan 22 '20 at 07:12
  • you can specify exit node from here https://b3rn3d.herokuapp.com/blog/2014/03/05/tor-country-codes – Sangram Jan 22 '20 at 07:14
  • if you get the solution please click on right tick and up vote for others take help from this question – Sangram Jan 22 '20 at 07:14