尝试使用python3连接到tor

时间:2018-09-27 17:33:08

标签: python-3.x python-requests tor

我一直试图在Mac上使用python连接tor。如果有帮助,我有python3和Mac Mojave。我的代码是:

import stem.process
from stem import Signal
from stem.control import Controller
from splinter import Browser

proxyIP = "127.0.0.1"
proxyPort = 9150

proxy_settings = {"network.proxy.type":1,
    "network.proxy.ssl": proxyIP,
    "network.proxy.ssl_port": proxyPort,
    "network.proxy.socks": proxyIP,
    "network.proxy.socks_port": proxyPort,
    "network.proxy.socks_remote_dns": True,
    "network.proxy.ftp": proxyIP,
    "network.proxy.ftp_port": proxyPort
}
browser = Browser('firefox', profile_preferences=proxy_settings)
browser.visit("http://www.icanhazip.com")

但是,每当我运行它时,都会发生错误:

Traceback (most recent call last):
  File "test.py", line 27, in <module>
    browser = Browser('firefox', profile_preferences=proxy_settings)
  File "/usr/local/lib/python3.6/site-packages/splinter/browser.py", line 64, in Browser
    return driver(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/splinter/driver/webdriver/firefox.py", line 78, in __init__
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

任何帮助将不胜感激。此致,泰勒

1 个答案:

答案 0 :(得分:0)

我不知道您的硒版本和geckodriver版本,所以我能回答的是upgrade them

  

pip install -U硒

     

here下载最新版本的geckodriver