RestClient::MethodNotAllowed: 405 Method Not Allowed GET response

3.4k Views Asked by At

I am performing a GET request in Ruby and not sure why I am sometimes getting the following stack trace.

RestClient::MethodNotAllowed: 405 Method Not Allowed
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/abstract_response.rb:48:in return!
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:269:in process_result
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:212:in block in transmit
/usr/lib/ruby/2.0.0/net/http.rb:852:in start
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:206:in transmit
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:68:in execute
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient/request.rb:35:in execute
[GEM_ROOT]/gems/rest-client-1.6.8/lib/restclient.rb:70:in get

It's especially confusing because the stack trace does not say which method is not allowed. What might be the cause of this error?

1

There are 1 best solutions below

1
On

You could try to rescue the exception. This way you can access the http_body of the response. If you're lucky, this might give you an insight on what went wrong.

begin
  RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}
rescue RestClient::Exception => e
  puts e.http_body
end