已完成 500 内部服务器错误; RestClient::NotAcceptable(406 不可接受)

Posted

技术标签:

【中文标题】已完成 500 内部服务器错误; RestClient::NotAcceptable(406 不可接受)【英文标题】:Completed 500 Internal Server Error; RestClient::NotAcceptable (406 Not Acceptable) 【发布时间】:2012-11-22 06:14:51 【问题描述】:

我是 Rails 和 *** 的新手,所以我会尽量明确。 我要求更改某人的项目,因此我获取了资源并尝试使其正常运行 我自己的工作计算机(在 Windows 上......)在我的本地浏览器上测试它(参见:rails s)。该项目假设正在运行,因为它已经在生产中,所以我认为问题来自我自己的工作环境。 安装完所有需要的 gem 后,运行 bundle install 并启动数据库服务器(项目使用的是 mongodb),我运行 rails server。该命令实际上有效,但是一旦我尝试使用本地主机地址(http://localhost:3000/)上的任何浏览器连接应用程序,我就会收到一个错误,我真的不明白原因......

这是我得到的日志:


Started GET "/" for 127.0.0.1 at 2012-12-04 14:51:30 +0100
Processing by HomeController#index as html
** [Localeapp] 1354629090-- Handling translation updates
** [Localeapp] 1354629090 - polling
** [Localeapp] API CALL: get https://api.localeapp.com/v1/projects/hhMxHgKAzj9p1dFuS0GnTTnemJ5F9dXLDuCa1KacQSymUcmTFk/translations.yml?updated_at=1354612995
** [Localeapp] ATTEMPT 1
Completed 500 Internal Server Error in 1192ms

RestClient::NotAcceptable (406 Not Acceptable):
  rest-client (1.6.7) lib/restclient/abstract_response.rb:48:in `return!'
  rest-client (1.6.7) lib/restclient/request.rb:230:in `process_result'
  rest-client (1.6.7) lib/restclient/request.rb:178:in `block in transmit'
  C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:745:in `start'
  rest-client (1.6.7) lib/restclient/request.rb:172:in `transmit'
  rest-client (1.6.7) lib/restclient/request.rb:64:in `execute'
  rest-client (1.6.7) lib/restclient/request.rb:33:in `execute'
  localeapp (0.5.2) lib/localeapp/api_caller.rb:66:in `make_call'
  localeapp (0.5.2) lib/localeapp/api_caller.rb:28:in `call'
  localeapp (0.5.2) lib/localeapp/api_call.rb:6:in `api_call'
  localeapp (0.5.2) lib/localeapp/poller.rb:43:in `poll!'
  localeapp (0.5.2) lib/localeapp/rails/controller.rb:14:in `handle_translation_updates'
  activesupport (3.2.3) lib/active_support/callbacks.rb:429:in `_run__744959596__process_action__507377612__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
  actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `each'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
  omniauth (1.1.1) lib/omniauth/strategy.rb:177:in `call!'
  omniauth (1.1.1) lib/omniauth/strategy.rb:157:in `call'
  omniauth (1.1.1) lib/omniauth/builder.rb:48:in `call'
  mongoid (2.5.0) lib/rack/mongoid/middleware/identity_map.rb:33:in `block in call'
  mongoid (2.5.0) lib/mongoid.rb:133:in `unit_of_work'
  mongoid (2.5.0) lib/rack/mongoid/middleware/identity_map.rb:33:in `call'
  sass (3.2.1) lib/sass/plugin/rack.rb:54:in `call'
  warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.1) lib/warden/manager.rb:34:in `catch'
  warden (1.2.1) lib/warden/manager.rb:34:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__286698992__call__202403334__callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  quiet_assets (1.0.1) lib/quiet_assets.rb:20:in `call_with_quiet_assets'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  airbrake (3.1.4) lib/airbrake/rack.rb:41:in `call'
  airbrake (3.1.4) lib/airbrake/user_informer.rb:12:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  railties (3.2.3) lib/rails/railtie/configurable.rb:30:in `method_missing'
  rack (1.4.1) lib/rack/deflater.rb:13:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  thin (1.4.1) lib/thin/connection.rb:80:in `block in pre_process'
  thin (1.4.1) lib/thin/connection.rb:78:in `catch'
  thin (1.4.1) lib/thin/connection.rb:78:in `pre_process'
  thin (1.4.1) lib/thin/connection.rb:53:in `process'
  thin (1.4.1) lib/thin/connection.rb:38:in `receive_data'
  eventmachine-1.0.0-x86 (mingw32) lib/eventmachine.rb:187:in `run_machine'
  eventmachine-1.0.0-x86 (mingw32) lib/eventmachine.rb:187:in `run'
  thin (1.4.1) lib/thin/backends/base.rb:63:in `start'
  thin (1.4.1) lib/thin/server.rb:159:in `start'
  rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
  rack (1.4.1) lib/rack/server.rb:265:in `start'
  railties (3.2.3) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.3) lib/rails/commands.rb:55:in `block in <top (required)>'
  railties (3.2.3) lib/rails/commands.rb:50:in `tap'
  railties (3.2.3) lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `require'
  script/rails:6:in `<main>'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (4.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (56.0ms)

这是提到的控制器:


class HomeController < ApplicationController
  def index
    @presenter = Home::IndexPresenter.new
    @article_presenter = Articles::IndexPresenter.new(Article.with_state(:published).last)
  end
end

如果有人可以帮助我,那就太好了。问我是不是忘了提什么。 谢谢你。

【问题讨论】:

【参考方案1】:

根本问题是 rest_client 请求的 URL 正在返回 HTTP 406 代码,您可以通过运行 curl 来查看,例如

curl --include https://api.localeapp.com/v1/projects/hhMxHgKAzj9p1dFuS0GnTTnemJ5F9dXLDuCa1KacQSymUcmTFk/translations.yml?updated_at=1354612995

(我刚刚注意到您使用的是 Windows 环境——如果您无法访问 curl,您可以安装几个工具来发出请求)

然后,在您的控制器中,似乎没有任何检查来查看来自 RestClient 调用的响应是否成功(2xx 状态)。由于 RestClient 引发异常,您的应用程序中会出现 500 错误。

因此,如果您不确定 URL 为何不起作用,则需要检查 localeapp.com 提供的 API

但鉴于 API 是一项外部服务,您可能还希望在您的软件中添加一些错误处理。有几种称为 RestClient 的东西,但如果它是由 archiloque 提供的,则文档提供了 good example of "result handling" here。

【讨论】:

感谢您的回答。但我很抱歉我没有理解它的所有部分......我在 Windows 环境中但是这个项目需要 curl 库所以我安装了它但我真的不知道它是用来做什么的。你觉得是环境问题吗?因为,我认为所有这些 gem 都已安装。 curl 是一个 unix 命令行工具,用于像浏览器一样获取(和发布等)URL。您不需要curl 可用——我只是用它来验证您发布的 URL 确实返回了 HTTP 状态 406。以这种方式隔离问题可以将问题缩小到 1) 您正在调用的 API api.localeapp.com 失败,或者 2) 您的应用程序没有发送正确的 URL,或者可能没有经过身份验证。我会在github.com/Locale/localeapp/wiki 或localeapp.com 了解详情。 你是对的!惊人的 !非常感谢:D!我终于明白问题出在“localeapp”的配置文件中。我关闭了轮询并使用 config/initializers/localeapp.rb 中的这两行在语言环境中发送工作: config.sending_environments = [] config.polling_environments = [] 非常感谢 :) !!

以上是关于已完成 500 内部服务器错误; RestClient::NotAcceptable(406 不可接受)的主要内容,如果未能解决你的问题,请参考以下文章

HTTP 错误 500.22 - 内部服务器错误(已检测到不适用于集成托管管道模式的 ASP.NET 设置。)

通过自动完成 JQuery 使用 WebService 的 500(内部服务器错误)

内部服务器错误 (500.21)

如何解决我的 PHP 页面上的 500 内部服务器错误?

服务器常见页面访问返回错误信息

Laravel 5.2 ajax 返回 500 内部服务器错误