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

uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable #103

Closed
bodrovis opened this issue Oct 31, 2014 · 44 comments
Closed

uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable #103

bodrovis opened this issue Oct 31, 2014 · 44 comments

Comments

@bodrovis
Copy link

Hello and thanks for the great gem.

Using the latest version I get an error uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable. Error trace:

        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:205:in
 `server_errors'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:242:in
 `response_error'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:256:in
 `unauthorized?'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:230:in
 `refresh_token_and_retry?'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:198:in
 `run_again?'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/request.rb:81:in
`run'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/actions/list.rb:9
5:in `fetch_page'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/actions/list.rb:8
5:in `next_page'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/actions/list.rb:5
0:in `find_next'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/actions/list.rb:2
1:in `block in list'
        from F:in `each'
        from F:in `each'
        from F:in `first'
        from F:in `first'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/actions/list.rb:1
3:in `first!'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/associations/has_
one.rb:17:in `block in has_one'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/associations/has_
attribute.rb:45:in `instance_eval'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/yt-0.13.7/lib/yt/associations/has_
attribute.rb:45:in `block in define_memoized_method'
        from F:in `title'
        from (irb):18
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/railties-4.1.6/lib/rails/commands/
console.rb:90:in `start'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/railties-4.1.6/lib/rails/commands/
console.rb:9:in `start'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/railties-4.1.6/lib/rails/commands/
commands_tasks.rb:69:in `console'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/railties-4.1.6/lib/rails/commands/
commands_tasks.rb:40:in `run_command!'
        from F:/Ruby/lib/ruby/gems/2.0.0/gems/railties-4.1.6/lib/rails/commands.
rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

This can be reproduced by creating a video resource like

v = Yt::Video.new url: 'https://www.youtube.com/watch?v=lE3a5-Kep3Y'

and issuing

v.title

or similar method (like comment_count).

@claudiofullscreen
Copy link
Contributor

Hello! I noticed the same kind of issues yesterday: YouTube API was having problems and glitches and would not let me retrieve data.

I tried your same query today and it worked… try again and tell me what you see, thanks!

[6] pry(main)> v = Yt::Video.new url: 'https://www.youtube.com/watch?v=lE3a5-Kep3Y'
=> #<Yt::Models::Video:0x007fa83b51f730 ...
[7] pry(main)> v.title
=> "Самый смешной футбольный матч в мире!"

@bodrovis
Copy link
Author

bodrovis commented Nov 1, 2014

@claudiofullscreen Strangely enough it is still the same. :(

@bodrovis
Copy link
Author

bodrovis commented Nov 6, 2014

Upd: Still the same. YT APIv2 works.

@bodrovis
Copy link
Author

@claudiofullscreen Okay, after a while I've returned to this problem and seems like there was glitches after all. Thank you for the reply!

@cqcn1991
Copy link

I'm getting the same problem.... Any idea?

@bodrovis
Copy link
Author

@cqcn1991 This can also be caused by the incorrect setup of your app in the Google Developers Console. You should enable YouTube Data API v3, Google+ API and YouTube Analytics.

I am planning to relese the updated version of my tutorial (http://www.sitepoint.com/youtube-rails/) on working with YT API and will cover all these steps.

@dustinleblanc
Copy link
Contributor

I am also now getting this problem @bodrovis I was initially following your tutorial to get started and had been successfully using youtube_it in development. It all of a sudden stopped working and I have now converted over to yt and I am getting this error as well.

I noticed it because video data was no longer getting fetched during my testing and using pry to inspect this:

def get_video_data
    begin
      video = Yt::Video.new id: uid
      binding.pry
      self.title = video.title
      self.author = video.author.name
    rescue
      self.title = ''
      self.author = ''
    end
  end

Inspecting with pry:

[1] pry(#<Video>)> video
=> #<Yt::Models::Video:0x007fbfb8a3a938 @auth=nil, @id="dnwW4d1Xkfw">
[2] pry(#<Video>)> video.title
NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable
from /Users/dustin/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/yt-0.13.8/lib/yt/request.rb:205:in `server_errors'
111

Not sure what is going on; I have all 3 APIs mentioned above working and was succesfully pulling this data a few days ago.

@bodrovis
Copy link
Author

@dustinleblanc Well, once again I can only recommend checking that you have enabled all the necessary APIs in the Google Console (see above). I didn't find any other causes for this problem unfortunately. The new version of tutorial is coming soon btw.

@dustinleblanc
Copy link
Contributor

@bodrovis looking forward to it, the first version was really helpful to get me started. thanks again! At least VCR was able to capture a successful transaction before it broke so that my test suite still runs :)

@bodrovis
Copy link
Author

@dustinleblanc If you are interested the source for the new tutorial is already on GitHub. Maybe it could help https://github.com/bodrovis/YTv3

@dustinleblanc
Copy link
Contributor

@bodrovis very cool. for kicks here is a gist of my model file with the logic involved; this is running in an existing refinery 1.0 site: https://gist.github.com/anonymous/2e05e3ea2c123f82c991

Ignore the binding.pry thats just there cause Im still working on troubleshooting :)

@dustinleblanc
Copy link
Contributor

With some input from some other developers we realized this is because OpenSSL::SSL::SSLErrorWaitReadable is not defined in Ruby 1.9.3 submitting a PR for the fix.

@moradtaleeb
Copy link

I'm using ruby 2.0.0p353 with rails "3.2.13" and I got the same error:

v.title
NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable

And yes, I have the 3 APIs enabled in google console.
What's wrong?

@dustinleblanc
Copy link
Contributor

@moradtaleeb you could try using our forked version of the gem at https://github.com/singlebrook/yt and see if it gets rid of your error then report back here. Rspec seems to run the specs fine for Ruby2 but the conditional check we added allowed the gem to operate fine on our ruby 1.9.3 / rails 3.2 site.

@moradtaleeb
Copy link

@dustinleblanc I used ruby 1.9.3 and with the gem you mentioned [ gem 'yt', '~> 0.13.8' ] and got the same error.

I tried to use the queries on the gem readme file too to make sure, and the same error appeared:

account = Yt::Account.new access_token: 'ya29.1.ABCDEFGHIJ'
channel = Yt::Channel.new id: 'UCxO1tY8h1AhOz0T4ENwmpow', auth: account
channel.subscribed?

NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:205:in server_errors' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:242:inresponse_error'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:256:in unauthorized?' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:230:inrefresh_token_and_retry?'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:198:in run_again?' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/request.rb:81:inrun'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:94:in fetch_page' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:84:innext_page'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:50:in find_next' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:21:inblock in list'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:9:in each' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:9:ineach'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:9:in first' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:9:infirst'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/actions/list.rb:13:in first!' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/associations/has_one.rb:17:inblock in has_one'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/associations/has_attribute.rb:45:in instance_eval' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/associations/has_attribute.rb:45:inblock in define_memoized_method'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/yt-0.13.12/lib/yt/models/channel.rb:108:in subscribed?' from (irb):3 from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/railties-3.2.21/lib/rails/commands/console.rb:47:instart'
from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/railties-3.2.21/lib/rails/commands/console.rb:8:in start' from /Users/moradtaleeb1/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/railties-3.2.21/lib/rails/commands.rb:41:in<top (required)>'
from script/rails:6:in `require'

@dustinleblanc
Copy link
Contributor

@moradtaleeb did you make sure to require the SB forked version of the gem? as in putting gem 'yt', github: 'singlebrook/yt', ref:'f9825b3c' in your gemfile?

@moradtaleeb
Copy link

@dustinleblanc now this worked :) thanks

@dustinleblanc
Copy link
Contributor

Great, at least that's a second person the patched version has worked for, I wouldn't rely on our patch indefinitely but it's good to get some confirmation that it is working outside our bubble

@claudiofullscreen
Copy link
Contributor

Hello! Let me recap what is happening to see if I understand everything:

  1. YouTube API has glitches, meaning that once in a while it will return a server error (such as connection timeout) even if the request is correct. Re-running the request after a while solves the issue.

  2. When YouTube API returns any sort of error (4xx, 5xx), Yt tries to understand if it's a server error by going through this code:

# Returns the list of server errors worth retrying the request once.
def server_errors
  [
    OpenSSL::SSL::SSLError,
    OpenSSL::SSL::SSLErrorWaitReadable,
    Errno::ETIMEDOUT,
    Errno::ENETUNREACH,
    Errno::ECONNRESET,
    Net::HTTPServerError
  ]
end
  1. If the version of Ruby that you have installed does not include one of these constants, then you will see an error such as the one described in this ticket:
NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable

Which versions of Ruby do not include the constant above? According to @dustinleblanc, the constant was introduced in Ruby 2.0. In fact the constant exists in Ruby Doc 2.0 and is missing in Ruby Doc 1.9.3.

Therefore, I think the correct solution to this issue is simply to merge #110.

What surprises me, though, is people reporting the same issue on Ruby 2.0.

@dustinleblanc @bodrovis What do you say? Is this issue on Ruby 2.0 really a thing? Can you still reproduce it? Otherwise I would just go and merge #110 and close this ticket.

@dustinleblanc
Copy link
Contributor

Yeah the reports of issues in Ruby 2.0 are a bit puzzling since when we tested it here at SB, specs ran fine on a ruby 2.0 install and error out on a 1.9.3 install. I am fairly positive travis-ci was reporting the same but its been some time since we looked into it. Can we run new builds against both versions on Travis and see if that can quickly confirm a difference?

@bodrovis
Copy link
Author

bodrovis commented Apr 9, 2015

@claudiofullscreen That's really strange but I can't reproduce it anymore with Ruby 2.1 at least (I just tried disabing YT API via Developers Console and running some API calls). I believe it is safe to merge this one.

@claudiofullscreen
Copy link
Contributor

@moradtaleeb Thanks to @dustinleblanc this issue is now fixed!

You don't have to reference a separate branch anymore, just add this to your Gemfile and you're good:

gem 'yt', '~> 0.14.3'

@moradtaleeb
Copy link

@claudiofullscreen @dustinleblanc now, it worked fine with ruby 1.9.3 and ruby 2.2.0 BUT didn't work with ruby 2.0.0

Note: Didn't test it on 2.1

@bodrovis
Copy link
Author

Yeah, seems like it is exactly the same I had with Ruby 2.0. I've switched to 2.1 some time ago...

@claudiofullscreen
Copy link
Contributor

@moradtaleeb Are you saying you still experience the same issue with Ruby 2.0 and yt 0.14.3?

@dustinleblanc
Copy link
Contributor

hmmm, perhaps the Ruby docs are inaccurate and that constant doesn't exist until 2.1? If that's the case we could probably advance the version constraint in both the test and lib files? Weird edge cases o_O

@dustinleblanc
Copy link
Contributor

https://github.com/ruby/ruby/search?utf8=%E2%9C%93&q=OpenSSL%3A%3ASSL%3A%3ASSLErrorWaitReadable&type=Code searching the 2_0_0 Branch of Ruby repo for the constant isn't yielding great results.

@bodrovis
Copy link
Author

Seems that's the case. Really weird.

@claudiofullscreen
Copy link
Contributor

The constant was introduced in ruby/ruby@0626d9

Therefore, the first version of Ruby with that constant should be Ruby 2.0.0-p195

@dustinleblanc @moradtaleeb Could you run ruby --version and print out exactly which version of Ruby 2 you are using? I suspect it might be a patch < p195

@dustinleblanc
Copy link
Contributor

I was testing with 1.9.3-p545 (site I initially was using this on) and
tested with 2.1.5 as well. Installing 2.0.0-p0 to test there

On Sun, Apr 12, 2015 at 9:11 PM claudiofullscreen notifications@github.com
wrote:

The constant was introduced in ruby/ruby@0626d9
ruby/ruby@0626d9

Therefore, the first version of Ruby with that constant should be Ruby
2.0.0-p195

@dustinleblanc https://github.com/dustinleblanc @moradtaleeb
https://github.com/moradtaleeb Could you run ruby --version and print
out exactly which version of Ruby 2 you are using? I suspect it might
be a patch < p195


Reply to this email directly or view it on GitHub
#103 (comment).

@dustinleblanc
Copy link
Contributor

2.0.0-p0 fails rspec tests. Can we spec the patch level in the code and tests? wowza

@claudiofullscreen
Copy link
Contributor

Thanks for your help! I guess that's the right thing to do… I'm curious
about other flavors of Ruby. JRuby? Rubinius? I don't really use them…

On Mon, Apr 13, 2015 at 8:54 AM, Dustin LeBlanc notifications@github.com
wrote:

2.0.0-p0 fails rspec tests. Can we spec the patch level in the code and
tests? wowza


Reply to this email directly or view it on GitHub
#103 (comment).

Claudio Baccigalupo | Software Writer | Fullscreen, Inc.
http://Fullscreen.net | +1.310.202.3333

@dustinleblanc
Copy link
Contributor

The original solution could work, simply include it if it is defined and then perhaps remove the reference to ruby 2.0 specifically, and just be like "some versions of Ruby don't have this 🤷"

@claudiofullscreen
Copy link
Contributor

🙇 You are so right!

@simplecircle
Copy link

I'm continuing to get NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable as well. with gem 'yt', '~> 0.14.5' and ruby 2.0.0p247 Any idea if there's a way to get past this problem? Thanks

@claudiofullscreen
Copy link
Contributor

@simplecircle Could you run the following commands and tell me what you see? Thanks:

~$ ruby --version
# ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
~$ irb
irb(main):001:0> require 'openssl'
# => true
irb(main):002:0> OpenSSL::SSL::SSLErrorWaitReadable
# => OpenSSL::SSL::SSLErrorWaitReadable

@simplecircle
Copy link

  • ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
  • true
  • NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable

@dustinleblanc
Copy link
Contributor

yuppers:

dustin@jarvis-mk-ii ~/code/ruby/yt [master *]
± % rbenv local 2.0.0-p195                                                                                                       !4292

dustin@jarvis-mk-ii ~/code/ruby/yt [master *]
± % irb                                                                                                                          !4293
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0> OpenSSL::SSL::SSLErrorWaitReadable
NameError: uninitialized constant OpenSSL::SSL::SSLErrorWaitReadable
    from (irb):2
    from /Users/dustin/.rbenv/versions/2.0.0-p195/bin/irb:12:in `<main>'
dustin@jarvis-mk-ii ~/code/ruby/yt [master *]
± % rbenv local 2.1.5                                                                                                            !4312

dustin@jarvis-mk-ii ~/code/ruby/yt [master *]
± % irb                                                                                                                          !4313
irb(main):001:0> require 'openssl'
=> true
irb(main):002:0> OpenSSL::SSL::SSLErrorWaitReadable
=> OpenSSL::SSL::SSLErrorWaitReadable
irb(main):003:0>

It's somewhere between those versions

@claudiofullscreen
Copy link
Contributor

@simplecircle I think I have fixed the issue. Can you download 0.14.6 and try again?

@simplecircle
Copy link

Thanks for that. I will. Before that I need to get a valid access token. My Web App (non iOS ) is using YT on it's behalf not a "User". Which Application type should I use for OAuth setup, "Web app", "Service acct" or "Installed app"? I have read so much conflicting info on this seemingly simple topic but don't know which scheme to choose. Thanks for the help

@bodrovis
Copy link
Author

Here you go, I've written an article on that: http://www.sitepoint.com/youtube-api-version-3-rails/ If you don't need any user interations, just request server key.

@claudiofullscreen
Copy link
Contributor

@simplecircle
Copy link

@bodrovis @claudiofullscreen Thanks for the links! I'll dig in. Once I get a token, I'll test the new patch and report back.

@simplecircle
Copy link

Looks like the ``0.14.6` fixed things. Thanks so much @claudiofullscreen

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

6 participants