简体   繁体   English

使用Python连接到Tor网络而不会出现“代理服务器拒绝连接”

[英]Connecting to the Tor network with Python without getting “Proxy server is refusing connection”

I've been trying to use Tor via Python only to come across the "Proxy server is refusing connection" error. 我一直试图通过Python使用Tor只遇到“代理服务器拒绝连接”错误。

I've trying this method using the Stem library: http://www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/ 我正在使用Stem库尝试这种方法: http//www.thedurkweb.com/automated-anonymous-interactions-with-websites-using-python-and-tor/

Any help to fixing this error? 有任何帮助修复此错误?

Here is the code: 这是代码:

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)

def interactWithSite(browser):
    browser.visit("http://dogdogfish.com/python-2/generating-b2b-sales-data-in-python/")
    browser.fill("comment", "But the thing is... Why would anyone ever want to do this? I must have thought that times...")
    browser.fill("author", "Pebblor El Munchy")
    browser.fill("email", "barack@tehwhitehouz.gov")
    browser.fill("url", "https://upload.wikimedia.org/wikipedia/en/1/16/Drevil_million_dollars.jpg")
    button = browser.find_by_name("submit")
    button.click()

interactWithSite(browser)

I deleted the SSL and FTP proxy and port settings and it worked. 我删除了SSL和FTP代理和端口设置,它工作正常。 I also used port 9150. 我也使用了端口9150。

Here is the working code: 这是工作代码:

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.socks": proxyIP,
    "network.proxy.socks_port": proxyPort,
    "network.proxy.socks_remote_dns": True,
}
browser = Browser('firefox', profile_preferences=proxy_settings)

def interactWithSite(browser):
    browser.visit("http://dogdogfish.com/python-2/generating-b2b-sales-data-in-python/")
    browser.fill("comment", "But the thing is... Why would anyone ever want to do this? I must have thought that times...")
    browser.fill("author", "Pebblor El Munchy")
    browser.fill("email", "barack@tehwhitehouz.gov")
    browser.fill("url", "https://upload.wikimedia.org/wikipedia/en/1/16/Drevil_million_dollars.jpg")
    button = browser.find_by_name("submit")
    button.click()

interactWithSite(browser)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM