如何解决使用休息客户端文件上传在 Yandex 上进行 Ruby 反向图像搜索
我正在尝试从 ruby 中的这个堆栈溢出问题中克隆最高答案
Reverse search an image in Yandex Images using Python
require 'rest-client'
require 'pry'
response = RestClient.post 'https://yandex.com/images/search',proxy: 'http://1.1.1.1:8080',params: {rpt: 'imageview',format: 'json',request: '{"blocks":[{"block":"b-page_type_search-by-image__link"}]}'},:upload => File.new("/home/alex/Desktop/yandex_search/t2.jpg",'rb'),multipart: true
binding.pry
我无法上传文件。不断收到回复 "Yandex.Images 中空请求的搜索结果"
解决方法
基于 python 实现,看起来参数应该作为查询参数发送。
告诉 RestClient 将其作为查询参数发送的方法是使用 headers 参数中的 params 值。
require 'rest-client'
query_strings = {rpt: 'imageview',format: 'json',request: '{"blocks":[{"block":"b-page_type_search-by-image__link"}]}'}
RestClient.proxy = "http://1.1.1.1:8080"
result = RestClient.post(
"https://yandex.com/images/search",{:upfile => File.new("/home/alex/Desktop/yandex_search/t2.jpg",'rb')},{params: query_strings,multipart: true}
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。