AnA*_*ice 5 ruby-on-rails ruby-on-rails-3
我从delayed_job得到了以下回复:
[Worker(XXXXXX pid:3720)] Class#XXXXXXX failed with URI::InvalidURIError: bad URI(is not URI?): https://s3.amazonaws.com/cline-local-dev/2/attachments/542/original/mac-os-x[1].jpeg?AWSAccessKeyId=xxxxxxxx&Expires=1295403309&Signature=xxxxxxx%3D - 3 failed attempts
Run Code Online (Sandbox Code Playgroud)
这个URI来自我的应用程序的方式是.
在我的user_mailer中我做:
@comment.attachments.each do |a|
attachments[a.attachment_file_name] = open(a.authenticated_url()) {|f| f.read }
end
Run Code Online (Sandbox Code Playgroud)
然后在我的附件模型中:
def authenticated_url(style = nil, expires_in = 90.minutes)
AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in => expires_in, :use_ssl => attachment.s3_protocol == 'https')
end
Run Code Online (Sandbox Code Playgroud)
话虽这么说,是否有一些类型的URI.encode或解析我可以做什么来防止有效的URI(因为我检查URL在我的浏览器中工作)错误和杀死rails 3中的delayed_job?
谢谢!
Ruby 有(至少)两个处理 URI 的模块。
URI是标准库的一部分。
Addressable::URI是一个单独的 gem,并且更全面,并且声称符合规范。
使用任一方法解析 URL,使用 gem 的方法修改任何参数,然后to_s在传递之前使用它进行转换,这样就可以开始了。
我尝试了 ' open( URI.parse(URI.encode( a.authenticated_url() )) ' 但出现 OpenURI::HTTPError: 403 Forbidden 错误
如果您通过浏览器导航到该页面并且成功,然后通过代码直接访问该页面失败,则可能缺少 cookie 或会话状态。您可能需要使用诸如Mechanize之类的工具,它将保持该状态,同时允许您浏览网站。
编辑:
require 'addressable/uri'
url = 'http://www.example.com'
uri = Addressable::URI.parse(url)
uri.query_values = {
:foo => :bar,
:q => '"one two"'
}
uri.to_s # => "http://www.example.com?foo=bar&q=%22one%20two%22"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8421 次 |
| 最近记录: |