Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to open TCP connection to images.unsplash.com:443 (execution expired) (Net::OpenTimeout) #88

Closed
Adesoji1 opened this issue Nov 1, 2023 · 1 comment

Comments

@Adesoji1
Copy link

Adesoji1 commented Nov 1, 2023

Steps to Reproduce

require 'unsplash'
require 'open-uri'
require 'net/http'

Configure the Unsplash gem

Unsplash.configure do |config|
config.application_access_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.application_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.utm_source = "Recommendation_Travels"
end

Search for photos with the keyword "Dubai"

search_results = Unsplash::Photo.search("Dubai")

Initialize a counter for file naming

counter = 1

Download the photos and trigger the download tracking

search_results.each do |photo|

Format the counter to have leading zeros, creating a filename like dubai_001.jpg

filename = "dubai_#{format('%03d', counter)}.jpg"

Download the photo with an extended timeout (e.g., 30 seconds)

download_url = photo.urls.full
uri = URI(download_url)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30 # Set the timeout to 30 seconds

response = http.request_get(uri)
if response.code.to_i == 200
File.open(filename, 'wb') do |file|
file.write response.body
end
else
puts "Failed to download photo: HTTP response code #{response.code}"
end

Trigger the download tracking for attribution

Unsplash::Photo.find(photo.id).track_download

Increment the counter for the next filename

counter += 1
end

puts "Downloaded and tracked #{search_results.size} photos of Dubai."

Observed Behaviour

Image or video please.

Expected Behaviour

ruby download_photo.rb
W, [2023-11-01T21:32:13.826060 #162007] WARN -- : The tags property in this endpoint is deprecated. https://changelog.unsplash.com/deprecations/2021/07/12/tags-search-deprecation.html
Traceback (most recent call last):
16: from download_photo.rb:56:in <main>' 15: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in method_missing'
14: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in each' 13: from download_photo.rb:66:in block in

'
12: from /usr/lib/ruby/2.7.0/net/http.rb:1393:in request_get' 11: from /usr/lib/ruby/2.7.0/net/http.rb:1483:in request'
10: from /usr/lib/ruby/2.7.0/net/http.rb:933:in start' 9: from /usr/lib/ruby/2.7.0/net/http.rb:1485:in block in request'
8: from /usr/lib/ruby/2.7.0/net/http.rb:1492:in request' 7: from /usr/lib/ruby/2.7.0/net/http.rb:1518:in transport_request'
6: from /usr/lib/ruby/2.7.0/net/http.rb:1567:in begin_transport' 5: from /usr/lib/ruby/2.7.0/net/http.rb:958:in connect'
4: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:193:in timeout' 3: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:186:in block in timeout'
2: from /usr/lib/ruby/2.7.0/net/http.rb:960:in block in connect' 1: from /usr/lib/ruby/2.7.0/net/http.rb:960:in open'
/usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize': Failed to open TCP connection to images.unsplash.com:443 (execution expired) (Net::OpenTimeout)

Technical Notes

  • Rubv version 2.7

Can anyone help me out? i want to download the pictures of Dubai

@Adesoji1
Copy link
Author

Connectivity issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant