Mechanize :: ResponseCodeError:501

时间:2014-04-15 16:46:31

标签: ruby-on-rails ruby-on-rails-4 proxy mechanize tor

在Ubuntu上使用Tor并尝试代理Mechanize

$ tor
Apr 15 11:40:10.024 [notice] Tor v0.2.4.21 (git-c5a648cc6f218339) running on Linux with Libevent 2.0.19-stable and OpenSSL 1.0.1c.
Apr 15 11:40:10.024 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Apr 15 11:40:10.024 [notice] Read configuration file "/etc/tor/torrc".
Apr 15 11:40:10.029 [notice] Opening Socks listener on 127.0.0.1:9050
Apr 15 11:40:10.029 [warn] Could not bind to 127.0.0.1:9050: Address already in use. Is Tor already running?
Apr 15 11:40:10.029 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.
Apr 15 11:40:10.029 [err] Reading config failed--see warnings above.

agent = Mechanize.new
agent.set_proxy('127.0.0.1', 9050)
agent.user_agent_alias = 'Mac Safari'
agent.get("http://www.linkedin.com/in/username")
=> Mechanize::ResponseCodeError: 501 => Net::HTTPNotImplemented for http://www.linkedin.com/in/username -- unhandled response
from /home/tristan/.rvm/gems/ruby-2.1.1/gems/mechanize-2.7.2/lib/mechanize/http/agent.rb:306:in `fetch'
from /home/tristan/.rvm/gems/ruby-2.1.1/gems/mechanize-2.7.2/lib/mechanize.rb:432:in `get'
from (irb):5
from /home/tristan/.rvm/gems/ruby-2.1.1/gems/railties-4.0.4/lib/rails/commands/console.rb:90:in `start'
from /home/tristan/.rvm/gems/ruby-2.1.1/gems/railties-4.0.4/lib/rails/commands/console.rb:9:in `start'
from /home/tristan/.rvm/gems/ruby-2.1.1/gems/railties-4.0.4/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'

如何解决这个问题?真的很难尝试代理这个!谢谢!

1 个答案:

答案 0 :(得分:1)

您在mechanize中设置的代理是HTTP代理,而不是socks5代理。 Tor使用socks代理而不是HTTP代理。默认情况下,它会在端口9050上打开socks代理。

我建议您使用privoxy,它允许您在端口9050上传递socks代理上的请求。