telegram-bot-ruby icon indicating copy to clipboard operation
telegram-bot-ruby copied to clipboard

execution expired (Faraday::ConnectionFailed)

Open ghost opened this issue 7 years ago • 14 comments

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

ghost avatar May 19 '17 09:05 ghost

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.

ivanovaleksey avatar May 19 '17 12:05 ivanovaleksey

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

ghost avatar May 19 '17 12:05 ghost

Hey, how to install API 3.0 from PR's branch, or when the changes will be pushed into master branch, so all the users can update simply gem?

ghost avatar May 28 '17 14:05 ghost

PR with new api will be merged in a few days, sorry for delay

atipugin avatar May 28 '17 15:05 atipugin

@atipugin I have the same error. What the status of the issue?

nbulaj avatar Jul 24 '17 10:07 nbulaj

@nbulaj which gem version do you use?

ivanovaleksey avatar Jul 24 '17 10:07 ivanovaleksey

@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'

nbulaj avatar Jul 24 '17 10:07 nbulaj

@nbulaj could you provide steps to reproduce the issue? Code sample on Gist would be perfect.

ivanovaleksey avatar Jul 24 '17 10:07 ivanovaleksey

Same error. If I make simple direct HTTP request via curl, it's OK.

curl https://api.telegram.org/bot<token>/sendMessage POST -d 'chat_id=@some_chant&text=Hello'

But telegram-bot-ruby returns Faraday::ConnectionFailed. I've tried to make direct requests via net/http, httparty, rest-client. All these gems can not establish connection to api.telegram.org:443.

Sample debug info from request: opening connection to api.telegram.org:443... And that's all.

Timeout error trace:

from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:904:in `initialize': execution expired (Net::OpenTimeout)
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:904:in `open'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:904:in `block in connect'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/timeout.rb:103:in `timeout'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:902:in `connect'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:887:in `do_start'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:876:in `start'
from /Users/this_user/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:1407:in `request'
from /Users/this_user/.rvm/gems/ruby-2.4.1@exchangarator/gems/httparty-0.15.6/lib/httparty/request.rb:142:in `perform'
from /Users/this_user/.rvm/gems/ruby-2.4.1@exchangarator/gems/httparty-0.15.6/lib/httparty.rb:563:in `perform_request'
from /Users/this_user/.rvm/gems/ruby-2.4.1@exchangarator/gems/httparty-0.15.6/lib/httparty.rb:505:in `post'
from /Users/this_user/.rvm/gems/ruby-2.4.1@exchangarator/gems/httparty-0.15.6/lib/httparty.rb:605:in `post'
from app.rb:19:in `<main>'

Tried on both ruby-2.3.3 and 2.4.1. OpenSSL 1.0.2l. MacOSX 10.12.4.

pashagray avatar Aug 03 '17 16:08 pashagray

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.

Xasin avatar Oct 06 '17 15:10 Xasin

Same problem.

/Users/checkraiser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/net/http.rb:904:in `initialize': execution expired (Faraday::ConnectionFailed)

Any solution ?

revskill10 avatar Dec 26 '17 20:12 revskill10

I hava same problem. my solutuion is change DNS on my WiFi router. when DNS is 1.1.1.1 works fine, but 168.126.63.1(Korea - KT, default) is not work.

sorry. same problem again.

NunciosChums avatar Oct 31 '18 07:10 NunciosChums

Any solve to this? I have the same problem. In production works fine, but not in development mode

ronnierios avatar Feb 05 '19 00:02 ronnierios

@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"]

NunciosChums avatar Feb 05 '19 02:02 NunciosChums

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Feb 19 '23 15:02 github-actions[bot]