socksify-ruby icon indicating copy to clipboard operation
socksify-ruby copied to clipboard

undefined method `socks_proxy' for Net::HTTP:Class (NoMethodError)

Open da2x opened this issue 3 years ago • 5 comments

irb(main):001:0> require 'socksify/http'
=> true
irb(main):003:0> Net::HTTP.socks_proxy('127.0.0.1', 9050)
(irb):3:in `<main>': undefined method `socks_proxy' for Net::HTTP:Class (NoMethodError)
Did you mean?  SOCKSProxy                                                            
        from /usr/share/gems/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'         
        from /usr/bin/irb:25:in `load'                                               
        from /usr/bin/irb:25:in `<main>'

ruby 3.1.2p20 socksify 1.7.1

da2x avatar Sep 01 '22 07:09 da2x

Hi @da2x, it seems like you're trying to use the socks_proxy method with the Net::HTTP class, but it's not defined in the socksify gem. Instead, you should use the Socksify::HTTP class, which inherits from Net::HTTP and includes the socks_proxy method. Here's the corrected code:

require 'socksify/http'

# Use Socksify::HTTP instead of Net::HTTP
Socksify::HTTP.socks_proxy('127.0.0.1', 9050)

By using the Socksify::HTTP class instead, you can now properly call the socks_proxy method without encountering the NoMethodError.

kornate avatar May 03 '23 19:05 kornate

@da2x, does @kornate's answer resolve your issue?

MatzFan avatar May 07 '23 18:05 MatzFan

I followed the README and got the same error. Still getting it with the suggested fix.

> irb
>> require 'socksify/http'
=> true
>> Socksify::HTTP
(irb):2:in `<main>': uninitialized constant Socksify::HTTP (NameError)
	from /Users/kencollins/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/irb-1.6.4/exe/irb:9:in `<top (required)>'
	from /Users/kencollins/.rbenv/versions/3.2.1/bin/irb:25:in `load'
	from /Users/kencollins/.rbenv/versions/3.2.1/bin/irb:25:in `<main>'

metaskills avatar May 31 '23 11:05 metaskills

I see the issue... I'm not sure how this gem is being published, but the code looks nothing like the what is in the v1.7.1 GitHub tag. Lots of things are concatenated in a single lib/socksify.rb and there are only two files in lib... http.rb and debug.rb.

metaskills avatar May 31 '23 11:05 metaskills

I can confirm that after changing my Gemfile to this, the code in the README works.

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'socksify', github: 'astro/socksify-ruby', ref: 'v1.7.2'

metaskills avatar May 31 '23 12:05 metaskills