Heroku 应用程序:RestClient::InternalServerError

发布于 2024-11-28 16:11:42 字数 1652 浏览 1 评论 0原文

我在 myapp.heroku.com 构建了一个网络应用程序,其中“myapp”实际上是由 heroku 生成的随机名称。当我用网络浏览器点击它时,它就起作用了。当我使用 Ruby Rest-Client (gem rest-client v1.6.3) 进行如下操作时:

irb(main):024:0> response=RestClient.get "http://myapp.heroku.com"

它会出现以下错误:

RestClient::InternalServerError: 500 Internal Server Error
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-    1.6.3/lib/restclient/abstract_response.rb:48:in `return!'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:228:in `process_result'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:176:in `block in transmit'
    from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:170:in `transmit'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:64:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:33:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient.rb:68:in `get'
    from (irb):24
    from C:/Ruby192/bin/irb:12:in `<main>'

当我使用具有更知名 URL 的相同客户端时,例如“http://www.google.com”。 com”,或“http://www.heroku.com”,它工作正常,URL 的内容下载,一切都很好。当我使用相同的客户端和在“http://localhost:3000”运行的应用程序版本时,它也工作得很好。

我的rest-client客户端中是否缺少某些内容,导致它无法从heroku.com托管的应用程序获取数据?

============ 编辑====附加信息===========

睡在上面后,我尝试了:

irb> require 'net/http'
irb> NET::HTTP.get_print URI.parse "http://myapp.heroku.com"

效果很好。

I have built a web app at myapp.heroku.com where "myapp" is actually the random name generated by heroku. When I hit it with my web browser it works. When I hit it with Ruby Rest-Client (gem rest-client v1.6.3) as follows:

irb(main):024:0> response=RestClient.get "http://myapp.heroku.com"

It craps out with the following:

RestClient::InternalServerError: 500 Internal Server Error
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-    1.6.3/lib/restclient/abstract_response.rb:48:in `return!'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:228:in `process_result'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:176:in `block in transmit'
    from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:170:in `transmit'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:64:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:33:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient.rb:68:in `get'
    from (irb):24
    from C:/Ruby192/bin/irb:12:in `<main>'

When I use the same client with better known URLs, such as "http://www.google.com", or "http://www.heroku.com", it works fine, the content of the URL downloads, and everything is good. When I use the same client with a version of the application running at "http://localhost:3000", it works fine too.

Am I missing something in my rest-client client which prevents it from GETting data from an app hosted at heroku.com?

============ EDIT ==== additional info ===========

After sleeping on it, I tried:

irb> require 'net/http'
irb> NET::HTTP.get_print URI.parse "http://myapp.heroku.com"

It worked fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆依然 2024-12-05 16:11:42

这里可能有很多原因;

如果您使用单个测功机,它会发出请求,但随后返回站点,但没有可用的测功机来处理请求,因此会超时。

在某些情况下,服务器无法与其外部地址进行对话,但我认为这种情况不太可能发生,更可能是动态问题?

约翰.

There could be a number of reasons here;

If you are using a single dyno, it goes out to make the request but then it comes back to the site but there isn't a dyno available to process the request so it times out.

There can be situations where a server is unable to talk back to itself on it's external address but I don't think this is likely to be the case, more likely a dyno issue perhaps?

John.

但可醉心 2024-12-05 16:11:42

我犯傻了。

在检查“heroku 日志”后,我发现代码中存在导致 500 错误的异常。异常是因为 heroku 中的 PG 数据库和我本地的 SQLite3 数据库之间存在类型转换差异。一旦我修好了,一切都很顺利。我怀疑 500 错误还导致我的网站暂时无法访问,这就是为什么我的网站托管的子域没有返回任何内容。

这个故事的寓意是什么?休息客户端有效。赫罗库可以工作。 Rest-client (IMO) 不应抛出 500 异常,而应返回 HTTP 响应代码并让应用程序处理它。然而,如果我抱怨更多,我也将不得不 fork &使固定...

I goofed.

Upon checking "heroku logs", I found an exception in my code which caused the 500 error. The exception was because of a type casting difference between the PG database in heroku, and my local SQLite3 database. Once I fixed it, everything went well. I suspect that the 500 error also caused my site to be temporarily unaccessible, which is why the subdomain on which my site is hosted did not return anything.

Moral of the story? rest-client works. Heroku works. Rest-client (IMO) shouldn't throw exceptions for a 500, but just return the HTTP response code and let the app deal with it. However, if I whine more, I'll also have to fork & fix...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文