0

I am trying to clone the top answer from this stack overflow question in 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

I cannot get the file to upload. Keep getting a response "Search results for empty request in Yandex.Images"

Ali Ove
  • 71
  • 7

1 Answers1

2

Based on the python implementation it looks like the params should be sent as query params.

The way to tell RestClient to send it as query parameters is to use the params value in the headers parameter.

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}
)
Pafjo
  • 4,979
  • 3
  • 23
  • 31
  • That was spot on, just needed to get the response itself as JSON and it was as simple as reponse = JSON.parse(result), image_link = response["blocks"][0]["params"]["url"] – Ali Ove Mar 14 '21 at 23:50