I want to know how to write code about download image file over responging 403 error code in nim. I can't find simple example programming code about requested respond.body == binary and respond.code == 403 case on httpclient.
Example : below img_url may returns 403 code but the program gets a image file.
Ex. Ruby
request uri-open
img_url = "https://ssl.appsx.cloud/wp-content/uploads/2021/c/02/822ffc8d107a5790b48bdbafab024e72-750x1121.jpg"
URI.open(img_url) {|f|
uri = URI.parse(img_url)
filename = File.basename(uri.path)
open("./images/"#{filename}", "wb") do |out|
out.write(f.read)
end
}
Or
request uri-open
img_url = "https://ssl.appsx.cloud/wp-content/uploads/2021/c/02/822ffc8d107a5790b48bdbafab024e72-750x1121.jpg"
uri = URI.parse(img_url)
filename = File.basename(uri.path)
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
res = https.start do |http|
File.open("./images/#{filename}", "wb") do |out|
http.request_get(parsed_url.path) do |response|
response.read_body do |s|
out.write(s)
end
end
end
https = nil
#puts res.code
res = nil
Ex. Python
import requests
import os
img_url = "https://ssl.appsx.cloud/wp-content/uploads/2021/c/02/822ffc8d107a5790b48bdbafab024e72-750x1121.jpg
img_data = requests.get(image_url).content
filename = os.path.basename(image_url)
del image_url
with open("./images" + "/" + filename, 'wb') as handler:
handler.write(img_data)
handler.flush()
del img_data