telegram-bot-ruby: execution expired (Faraday::ConnectionFailed)

Hey, today after Telegram introduced Bot API 3.0 i’ve got error running my bot. Here is log

usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:880:in `initialize': execution expired (Faraday::ConnectionFailed)
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:880:in `open'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:878:in `connect'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:852:in `start'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/net/http.rb:1398:in `request'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:80:in `perform_request'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:38:in `block in call'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:85:in `with_net_http_connection'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/adapter/net_http.rb:33:in `call'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/request/url_encoded.rb:15:in `call'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/request/multipart.rb:15:in `call'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/rack_builder.rb:139:in `build_response'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/connection.rb:386:in `run_request'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/faraday-0.12.1/lib/faraday/connection.rb:186:in `post'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/api.rb:65:in `call'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/api.rb:53:in `method_missing'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/client.rb:30:in `fetch_updates'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/client.rb:25:in `listen'
        from /home/ubuntu/workspace/bot.rb:69:in `block in <main>'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/client.rb:18:in `run'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/telegram-bot-ruby-0.7.2/lib/telegram/bot/client.rb:8:in `run'
        from /home/ubuntu/workspace/bot.rb:48:in `<main>'

line 48 of my code : Telegram::Bot::Client.run(token) do |bot| line 69: bot.listen do |message|

Yesterday everything worked perfectly, so i suppose it’s something about new update from Bot API

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

@ronnierios me.

  1. I stopped use this library then direct call to telegram api url by rest-client
  2. add timeout=60 parameter to telegram api
url = "#{api_url}/getUpdates?offset=#{@offset.next}&timeout=60"
response = RestClient::Request.execute(method: :get, url: url, timeout: 5)
return unless response["ok"]

Same problem here. Upon using Telegram::Bot::Client.run(token), telegram-bot-ruby raises Faraday::ConnectionFailed after a time-out. Tried with the default Farady and net-http-persistent, on ruby 2.4.2, Ubuntu 14 LTS

Maybe Telegram changed something about how their API accepts connections? I can ping api.telegram.org, but I can’t use PavelTkachenko’s curl command (although that’s probably me using curl wrong).

Update, it seems as if the library can’t even resolve the hostname somehow? I have tried monitoring everything going to the Telegram API servers, using Wireshark. I can ping it fine, even open the URLs via my normal browser (which is actually kind of cool to play with), and all traffic is captured by Wireshark. When I try to start the Ruby program though, nothing appears. As in, absolutely nothing, not even a packet to resolve the hostname or similar.

Another interesting fact is that, when running the script from my Raspberry Pi, everything works just fine.

FYI, my current network setup involves using my Raspberry as a WiFi connector that then forwards and NATs internet connection to a LAN network that my computer runs on. However, it hasn’t caused me any problems connection-wise, and the fact that I can open the API URLs in my browser further supports that.

Update 2 Adding the hostname api.telegram.org to resolve to IP 149.154.167.200 inside /etc/hosts actually works. It’s a bit of a very messy thing though because this involves manual interaction. BUT it further backs up the theory of the code not resolving the hostname correctly!

As a temporary fix for short development, maybe this can work.

@ivanovaleksey telegram-bot-ruby (0.8.2)

Got:

/home/xxx/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:904:in ‘initialize’: execution expired >(Faraday::ConnectionFailed) from /home/xxx/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:904:in `open’

Sorry of that, i’m kinda new to github community. Thank you for your work, i’m looking forward for updates.

There is PR #118 which adds support for Bot API 3.0. Once the work is done you could test by installing the gem from PR’s branch.

P. S. Please format your message. Use triple backticks for multiline code.