Closed JohnBat26 closed 10 years ago
support OK ;)
Hmm I set:
conn = Faraday.new(url, ssl: {verify: false}) do |builder| builder.response :follow_redirects, :limit => 3, :standards_compliant => false, :cookie => :all builder.adapter :typhoeus end
Request sended but with net_http ! How I can switch to typhoeus of em_http? In 0.7.X typhoeus worked well.
My stack trace: https://gist.github.com/3743068
I set typhoeus or em_http adapter, but in logs:
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in new' /home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in
create_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:74:in perform_request' /home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:37:in
call'
server get response with status 503 but net_http get error: Error undefined method `strip' for nil:NilClass
You're initializing a Faraday connection like this:
conn = Faraday.new(url, ssl: {verify: false}) do |builder|
builder.response :follow_redirects, :limit => 3, :standards_compliant => false, :cookie => :all
builder.adapter :typhoeus
end
It looks OK. But are you using the same connection to make requests? You haven't showed us code with which you perform requests using Faraday. Maybe you're using two different Faraday connections.
Tip: try using follow_redirects with just default options:
builder.response :follow_redirects
I see in debug mode that object conn use adapter typhoeus, but in logs I see net_http?! Why?
I use next code:
require 'faraday'
require 'faraday_middleware'
require 'em-http'
require 'typhoeus'
module MediationHelper
# Parameters:
# url = args[:url]
# method = args[:method] || :post
# adapter = args[:adapter] || :net_http
# body = args[:body] || ""
# params = args[:params]
# authentication = args[:auth]
# headers = args[:headers] || {'Content-Type' => 'text/xml; charset=utf-8'}
# timeout = args[:timeout] || 60
# open_timeout = args[:open_timeout] || 60
#
def self.send_http_request(args)
url = args[:url]
method = args[:method] || :post
adapter = args[:adapter] || :net_http
params = args[:params]
body = args[:body] || ""
authentication = args[:auth]
headers = args[:headers] || {'Content-Type' => 'text/xml; charset=utf-8'}
timeout = args[:timeout] || 60
open_timeout = args[:open_timeout] || 60
conn = Faraday.new(url, ssl: {verify: false}) do |conn|
conn.response :follow_redirects
conn.adapter adapter
end
conn.basic_auth(args[:username], args[:password]) if authentication
response = conn.send(method) do |req|
req.headers.update headers
req.body = body
req.params = params if params
req.options = {
:timeout => timeout, # open/read timeout Integer in seconds
:open_timeout => open_timeout, # read timeout Integer in seconds
}
end
response
end
end
next I invoke this:
response_for_login_request = MediationHelper.send_http_request(:url => url,
:body => login_request_xml,
:adapter => :typhoeus
:headers => {'Content-Type' => "text/xml; charset=utf-8",
'Cookie' => my__cookie,
'SOAPAction' => '""'})
I set: conn.response :follow_redirects and get error still: Exception NoMethodError Error undefined method `strip' for nil:NilClass
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1435:in `block in initialize_http_header'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1433:in `each'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1433:in `initialize_http_header'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1862:in `initialize'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in `new'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in `create_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:74:in `perform_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:37:in `call'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday_middleware-0.8.8/lib/faraday_middleware/response/follow_redirects.rb:76:in `perform_with_redirection'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday_middleware-0.8.8/lib/faraday_middleware/response/follow_redirects.rb:65:in `call'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/connection.rb:226:in `run_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/connection.rb:99:in `post'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/mediation_helper.rb:50:in `send_http_request'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/broadworks_helper.rb:81:in `authenticate'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/broadworks_helper.rb:121:in `init_broadworks_session'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/jobs/webex_requests_job.rb:24:in `block in perform'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:239:in `block in each'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:238:in `upto'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:238:in `each'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/jobs/webex_requests_job.rb:18:in `perform'
Sorry. Its my mistake. I do 2 request, and forget about second request with default adapter. With typhoeus this error don't appear. But what do with net_http adapter and it error: undefined method `strip' for nil:NilClass ?
Sorry I forgot to reply to this. You were probably passing a header value that was nil, and net_http was trying to process the header value as a string.
To work around it, ensure that any header that you pass actually has a string value.
Does faraday 0.8.X support typhoeus client?