【问题标题】:Rails w/ Google API Client: header field value cannot include CR/LF带有 Google API 客户端的 Rails:标头字段值不能包含 CR/LF
【发布时间】:2018-07-07 04:32:01
【问题描述】:
ArgumentError in Users::OmniauthCallbacksController#google_oauth2
header field value cannot include CR/LF

真的不确定这个错误来自哪里。

我正在使用 ruby​​ 2.5、Rails 5 和 google-api-client 0.8.2

任何想法如何解决或我可以提供什么信息来使这个问题更具信息性?

更新:当我尝试使用 Google 的 API 进行授权时,我的日志显示了这一点

Google::APIClient::Request Sending API request get https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest {"User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n (gzip)", "Accept-Encoding"=>"gzip", "Content-Type"=>""}

根据我的研究,CRLF 是“\r\n”字符,对吧?

所以"User-Agent"=>"hello U/1.0.0 google-api-ruby-client/0.8.2 Mac OS X/10.13.4\n 可能是问题所在。

所以我的问题是——如何在我的请求中访问用户代理来解决 Rails 5 的这个问题?

【问题讨论】:

    标签: ruby-on-rails google-calendar-api google-api-ruby-client


    【解决方案1】:

    使用Google::APIClient 时,生成的User-Agent 可能包含CRLF。它可以在构造函数中被覆盖。示例:

    Google::APIClient.new(application_name: 'Foo', application_version: '1.0', user_agent: 'Foo/1.0 google-api-ruby-client/0.8.6 Linux/4.15.0-65-generic (gzip)')
    

    【讨论】:

    • 它对我有用。比从 0.7 升级到 0.20 和更改代码要简单得多。谢谢!
    • 更新对我没有任何帮助。
    【解决方案2】:

    您可以修改 user_agent 字符串以删除 CR/LF。我正在使用 Rails 4.1.8 和google-api-client 版本`

      @api_client = Google::APIClient.new(:application_name=>"Chronos", :application_version=>0)
      # work around a bug that puts a CR/LF in the user agent string
      @api_client.user_agent = @api_client.user_agent.gsub("\n", "")
    

    【讨论】:

      【解决方案3】:

      将 gem google-api-client 更新到版本 0.20.0。它解决了问题,但需要对应用程序进行其他更改

      【讨论】:

        【解决方案4】:

        更新 google-api-client gem 的版本对我有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-09-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-15
          • 2021-08-15
          • 1970-01-01
          相关资源
          最近更新 更多