[Ruby] TypeError : can't convert Pathname into String

Official OpenTok Server-Side libraries

[Ruby] TypeError : can't convert Pathname into String

Postby zgredzik » Thu Aug 09, 2012 2:44 am

Dear fellow Developers, Programmers, Computer Scientists and/or anyone else capable of solving this mystery,

While trying to run some simple code (quoted below) I wrote in Ruby (using RoR) that is supposed to create an OpenTok session I receive the mentioned error.
api_key = "4W3S0M3K3Y"
api_secret = "it's secret!"

opentok = OpenTok::OpenTokSDK.new api_key, api_secret
session_properties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "disabled"}
session = opentok.create_session request.remote_addr, session_properties # <--- this is the buggy line

ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
rails 3.2.6
opentok 0.0.7

A little bit of additional information I got when running the code from rails console:
irb(main):006:0> session = opentok.create_session "localhost", session_properties

TypeError: can't convert Pathname into String
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:776:in `initialize'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:776:in `new'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:776:in `connect'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:744:in `start'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/opentok-0.0.7/lib/open_tok/open_tok_sdk.rb:170:in `do_request'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/opentok-0.0.7/lib/open_tok/open_tok_sdk.rb:125:in `create_session'
from (irb):6
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from D:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I have searched the depths of the internet looking for a solution... unfortunately I failed.
The most fierce discussion regarding this topic that I have found is under this link, though I seem to be unable to comprehend what "follow the OpenTok API/Doc without using the gem" means.
The server-side documentation sends me off to an appropriate project at github where the Installation section tells me to install the gem (unless I've missed that particular piece of information about using the server-side API without the gem).

I would be grateful for any help at all that might get me closer to solving this problem.

Yours truly,
zgredzik (real tongue twister, I know)
Was this post helpful? (0)
zgredzik
 
Posts: 3
Joined: Thu Aug 09, 2012 1:26 am
Thumbs Up: 0

Re: [Ruby] TypeError : can't convert Pathname into String

Postby ankur » Thu Aug 09, 2012 8:51 am

Hey there,

That indeed looks like a strange issue but I'll try to help get to the bottom of it with you.

So the error seems to be thrown from the Net::HTTP module, specifically opening a connection to the api_url. I want to try and narrow the scope of where the problem is happening, so would you mind modifying your Ruby code a little like so?

Code: Select all
api_key = "4W3S0M3K3Y"
api_secret = "it's secret!"

opentok = OpenTok::OpenTokSDK.new api_key, api_secret, :api_url => 'https://staging.tokbox.com/hl'
session_properties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "disabled"}
session = opentok.create_session request.remote_addr, session_properties # <--- this is the buggy line


This assumes you are currently using staging, but if you are on production, you can change the value for :api_url to "https://api.opentok.com/hl". I want to make sure this URL is explicitly set because then we know what URL Net:HTTP should be requesting for.

-- Ankur
Was this post helpful? (0)
ankur
 
Posts: 356
Joined: Thu Jun 02, 2011 12:37 am
Thumbs Up: 12

Re: [Ruby] TypeError : can't convert Pathname into String

Postby zgredzik » Thu Aug 09, 2012 9:49 am

After applying the modification I still receive the same error and stack trace. But you've made me think...

Is there a possibility that the fix I've applied to bypass a problem with SSL certificate verification might be the root of all this evil?
config/initializers/fix_ssl.rb wrote:require 'open-uri'
require 'net/https'

module Net
. class HTTP
. . . alias_method :original_use_ssl=, :use_ssl=

. . . def use_ssl=(flag)
. . . . . self.ca_file = Rails.root.join('lib/ca-bundle.crt')
. . . . . self.verify_mode = OpenSSL::SSL::VERIFY_PEER
. . . . . self.original_use_ssl = flag
. . . end
. end
end

Although without that fix I'm getting the following error:
OpenSSL::SSL::SSLError in RoomsController#index
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

regarding the same line as before.

PS. Please forgive me if any of those problems seem trivial. I'm quite new to Ruby and sometimes I get a bit confused - mainly because of all the 'magic' hiding beneath RoR's scaffolding.
Was this post helpful? (0)
zgredzik
 
Posts: 3
Joined: Thu Aug 09, 2012 1:26 am
Thumbs Up: 0

Re: [Ruby] TypeError : can't convert Pathname into String

Postby ankur » Thu Aug 09, 2012 11:53 am

Nice detective work!

I think this is likely related, and I have one idea of a fix that would allow you to keep your code, its as simple as making the 'https' in the :api_url value to plain 'http'. We host the same endpoint for both standard HTTP and TLS/SSL. If you feel comfortable with standard HTTP transport you can keep it this way, but at the very least it should help us isolate the issue.

-- Ankur
Was this post helpful? (0)
ankur
 
Posts: 356
Joined: Thu Jun 02, 2011 12:37 am
Thumbs Up: 12

Re: [Ruby] TypeError : can't convert Pathname into String

Postby zgredzik » Thu Aug 09, 2012 2:05 pm

That was indeed one of the most simple yet rewarding solutions I have ever seen. The problem is fixed, the session id - acquired!
Thank you very much for all your help! For now I'm only learning how to use Ruby and OpenTok so the standard HTTP will be more than enough.
Was this post helpful? (0)
zgredzik
 
Posts: 3
Joined: Thu Aug 09, 2012 1:26 am
Thumbs Up: 0

Re: [Ruby] TypeError : can't convert Pathname into String

Postby ankur » Thu Aug 09, 2012 2:17 pm

I agree, that was fairly painless :)

Let us know if there's anything else we can help you out with. Or even if you want to show off something you've built, we would love to hear about it.

Thanks,

Ankur Oberoi
Was this post helpful? (0)
ankur
 
Posts: 356
Joined: Thu Jun 02, 2011 12:37 am
Thumbs Up: 12

Re: [Ruby] TypeError : can't convert Pathname into String

Postby hmost » Fri Dec 14, 2012 11:52 am

Hi! I know this is an old post but I too am very new to ruby and RoR, and am having the exact same issue. I had the same openSSL error and could only find a fix with the same edits above to the file fix_ssl.rb . This then resulted in the "can't convert Pathname into String" error which I assumed to be related, but am not sure how to solve. If you would mind sharing how your fix worked and why I'd really appreciate it. Thanks!
Was this post helpful? (0)
hmost
 
Posts: 1
Joined: Fri Dec 14, 2012 11:46 am
Thumbs Up: 0

Re: [Ruby] TypeError : can't convert Pathname into String

Postby jtsai » Mon Dec 17, 2012 3:17 pm

hmost wrote:Hi! I know this is an old post but I too am very new to ruby and RoR, and am having the exact same issue. I had the same openSSL error and could only find a fix with the same edits above to the file fix_ssl.rb . This then resulted in the "can't convert Pathname into String" error which I assumed to be related, but am not sure how to solve. If you would mind sharing how your fix worked and why I'd really appreciate it. Thanks!


Hi there.

Are you getting our latest library from github? Any other sources may be out-dated. http://qa.tokbox.com/test/dynamic_loading_TB.php

John
Was this post helpful? (0)
User avatar
jtsai
 
Posts: 4447
Joined: Wed Sep 14, 2011 3:00 pm
Thumbs Up: 195


Return to Supported Server API (PHP, Java, Ruby, Python)



Who is online

Users browsing this forum: No registered users and 1 guest

cron