Dear,
I'm receiving the following error in Rails 4 when I launch the code that was Previously working in Rails 3.
Error:
WebMock::NetConnectNotAllowedError (Real HTTP connections are disabled. Unregistered request: GET https://erpweb.customer.be/pas/bc/hosting/ws/rest/anonymous/yr_hot_jobs?client=030&language=en with headers {'Accept'=>'_/_', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/xml', 'User-Agent'=>'custom_agent'}
The problem occurs when launching this code:
def perform_request(verb, path, params = nil, body = nil)
conn = connection.dup
params ||= {}
# If params contains a token, it will used the `named` routes and
# set an authorization header
if params[:token]
path = ["named", path].join("/")
conn.headers["Authorization"] = "Basic #{params.delete(:token)}"
else
path = ["anonymous", path].join("/")
end
# All requests need to specify their sap client.
params = (params || {}).merge("client" => client_id)
# Sap expects each body sent to it to be xml-encoded.
conn.headers["Content-Type"] = "application/xml"
conn.send(verb, path) do |request|
log "Path : #{verb.upcase} #{default_url}#{path}"
log "Params : #{params.inspect}"
# log "Body : #{body.inspect[0..1000]}"
request.params = params if params
request.body = body if body
request.options[:timeout] = 120 # open/read timeout in seconds
# request.options[:open_timeout] = 15 # connection open timeout in seconds
end
end
You must be running your code in an environment where WebMock is enabled (a separate gem, not related to Faraday). It is preventing web requests from occurring. Usually this only happens in your test environment. If you want to allow web requests in your test environment, or for a specific test, you can use WebMock.disable! (but be sure to enable! it again when it's needed, assuming it is there for a reason)
Hi @DelawareConsulting, as @mltsy said above your code is fine, but you're probably executing it in a test environment where HTTP calls are blocked. You have to "stub" them using WebMock.
Here is a link to the documentation: https://github.com/bblimke/webmock#stubbing
This is completely unrelated to Faraday, so I'm going to close this Issue.
Most helpful comment
You must be running your code in an environment where WebMock is enabled (a separate gem, not related to Faraday). It is preventing web requests from occurring. Usually this only happens in your test environment. If you want to allow web requests in your test environment, or for a specific test, you can use
WebMock.disable!(but be sure toenable!it again when it's needed, assuming it is there for a reason)