ruby rest-client:使其永不超时?
我正在尝试使用 ruby rest-client 将大量图像上传到我正在编写的网站。我的代码如下所示:
RestClient.post url, :timeout => 90000000, :open_timeout => 90000000, :file_param => file_obj
但是,我收到此错误:
RestClient::RequestTimeout: Request Timeout
from /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:174:in `transmit'
from /Library/Ruby/
但是当我查看服务器日志时
Completed in 61493ms (View: 2, DB: 1) | 201 Created
,似乎没有任何原因导致超时。有人知道我是否未正确设置超时参数吗?
谢谢
I am trying to use ruby rest-client to upload a large number of images to a site that I'm writing. My code looks like:
RestClient.post url, :timeout => 90000000, :open_timeout => 90000000, :file_param => file_obj
However, I am getting this error:
RestClient::RequestTimeout: Request Timeout
from /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:174:in `transmit'
from /Library/Ruby/
But when I look at the server log
Completed in 61493ms (View: 2, DB: 1) | 201 Created
So there doesn't appear to be any reason why this is timing out. Anyone have any idea if there is a timeout param I am not correctly setting?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
此语法将超时设置为请求头(请参阅RestClient.post签名),如果您想使用超时参数,则必须使用:
请参阅:https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L12
This syntax sets the timeout as request header (see RestClient.post signature), if you want to use the timeout parameter you must use:
see: https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L12
查看文档,您可以通过 RestClient.execute 超时参数传递 -1:
它可以按如下方式使用:
Looking at the docs, you can pass -1 through RestClient.execute timeout param:
It can be used as follows:
我使用了以下代码,并且像理查德指出的那样工作起来
I have used following code and works like a charm as pointed out by Richard
我已经广泛使用 RestClient.get 和 RestClient.post,所以对我来说,“Monkey Patch”RestClient 更容易。如果可能的话,我建议使用
RestClient::Resource.new
或RestClient::Request.Execute
。但是,由于我很懒,并且不想在代码中交换
RestClient.get
/RestClient.post
的每次出现,所以我决定走捷径。我只是快速地将 RestClient.get/post 替换为 RestClient2.get/post 。
如果 RestClient::Request 指定了默认超时,那就太好了,例如:
I already use RestClient.get and RestClient.post extensively, so for me, it was easier to 'Monkey Patch' RestClient. I would recommend using
RestClient::Resource.new
orRestClient::Request.Execute
if possible.However, since I'm lazy, and don't want to go swap out every occurrence of
RestClient.get
/RestClient.post
in my code, I've decided to take a shortcut.And than I just just quick replaced RestClient.get/post with
RestClient2.get
/post.It would be nice, if
RestClient::Request
had a default timeout specified, like:我也有类似的问题。快速深入了解源代码就会发现这种不友好之处:
除非我遗漏了某些内容,否则超时选项不会传递给底层请求。是时候打个补丁了...
I'm having similar issues. A quick dive into the source reveals this bit of unfriendliness:
Unless I'm missing something, the timeout options aren't passed on to the underlying request. Time for a patch ...
RestClient::Resource.new() 允许您设置 :timeout 和 :open_timeout 值,当您使用资源的 get、post、put 等方法时,这些值将传递给 Request.execute 方法
The RestClient::Resource.new() allows you to set :timeout and :open_timeout values that will get passed to the Request.execute method, when you use the resource's get, post, put, etc methods