gpt4 book ai didi

ruby-on-rails - 法拉第代理 - 连接失败 - 到达文件末尾

转载 作者:行者123 更新时间:2023-12-05 04:28:50 28 4
gpt4 key购买 nike

我正在使用 OAuth2 gem 并尝试将其配置为通过代理进行调用。我遇到此错误 Faraday::ConnectionFailed: end of file reached 并且不确定我做错了什么。我以为这是证书,但我设法让 Curl::Easy 建立连接并发布数据。

非常感谢您为帮助我解决此问题所做的任何努力。提前致谢。

法拉第例子

我曾经抽取任务来和 Faraday 一起玩。

namespace :vgs do
task faraday: :environment do
Faraday.default_adapter = :net_http
ssl_cert_path = VGS.configuration.cert_path # "/path/to/sandbox.pem"

options = {
headers: { 'Content-Type' => 'application/json' },
ssl: { ca_file: ssl_cert_path },
proxy: VGS.proxy_uri, # => "https://<USERNAME>:<PASSWORD>@<VAULT>.sandbox.verygoodproxy.com:8443"
}

pp options

conn = Faraday.new(
'https://eoftqqzi7ii7mmn.m.pipedream.net',
options
)

data = {
card_number: 'tok_sandbox_sS27yztTZjuznHD1hmtgCS',
card_cvc: 'tok_sandbox_241N1r8hxoYDyqrUSmZ4ih',
card_expiration_date: '2212',
transaction_amount: 84.0
}

response = conn.post('/') do |req|
req.body = data.to_json
end

pp response
pp response.body
end
end

运行此任务会导致以下错误:

Faraday::ConnectionFailed: end of file reached
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:146:in `request_via_request_method'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:131:in `request_with_wrapped_block'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:122:in `perform_request'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:66:in `block in call'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-1.10.0/lib/faraday/adapter.rb:50:in `connection'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:64:in `call'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-1.10.0/lib/faraday/request/url_encoded.rb:25:in `call'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-1.10.0/lib/faraday/rack_builder.rb:154:in `build_response'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-1.10.0/lib/faraday/connection.rb:516:in `run_request'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/faraday-1.10.0/lib/faraday/connection.rb:281:in `post'
/Volumes/Dev/Work/Edge/edge/lib/tasks/vgs.rake:60:in `block (2 levels) in <main>'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'
/Users/jdeen/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `load'
<internal:/Users/jdeen/.rvm/rubies/ruby-3.1.1/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/Users/jdeen/.rvm/rubies/ruby-3.1.1/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
-e:1:in `<main>'

如果您能指出我可能做错了什么,我将不胜感激。

额外

代理文档:https://www.verygoodsecurity.com/docs/guides/outbound-connection

这是有效的 Curl::Easy。我使用 Curl::Easy variation 来确保它可能不是证书。

namespace :vgs do
task curl: :environment do
proxy = VGS.proxy_uri
uri = 'https://eoftqqzi7ii7mmn.m.pipedream.net'

options = {
card_number: 'tok_sandbox_sS27yztTZjuznHD1hmtgCS',
card_cvc: 'tok_sandbox_241N1r8hxoYDyqrUSmZ4ih',
card_expiration_date: '2212',
transaction_amount: 84.0
}

c = Curl::Easy.new(uri) do |http|
http.headers['Content-Type'] = 'application/json'
http.cacert = VGS.configuration.cert_path # "/path/to/sandbox.pem"
http.proxy_url = proxy
http.follow_location = true
http.ssl_verify_peer = true
http.post_body = options.to_json
http.post
end

puts "Response #{c.status}: #{c.body}"
end
end

最佳答案

我和 vgs 有同样的问题,这有助于解决这个问题:

require 'faraday'
require 'typhoeus'
require 'typhoeus/adapters/faraday'

conn = Faraday.new do |faraday|
faraday.adapter :typhoeus, http_version: :httpv2_0
end

enforcing Faraday adapter :typhoeus to use HTTP/2 for requests

此外,我在我的 M1 mac 上发出请求时遇到问题,通过在我的 ~/.zshrc 文件中导出 ENV 变量来解决(项目的 .env 不起作用对我来说)

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

https://github.com/rails/rails/issues/38560

关于ruby-on-rails - 法拉第代理 - 连接失败 - 到达文件末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72511061/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com