Hi, I'm trying to log in into Webfaction using the XMLRPC API and Ruby library. Problem is:

require 'xmlrpc/client'
server = XMLRPC::Client.new2("https://api.webfaction.com/")
server.call("login", "user", "password")

While trying this simple example found in the docs, the login call to the server results in:

C:/Ruby193/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

As you can see. I'm using Windows Ruby 1.9.3p0 . Any ideas?

asked 16 Dec '11, 15:11

Phrozen's gravatar image

Phrozen
51129
accept rate: 40%

Can it be something to do with the API being down? If I go to https://api.webfaction.com/ I got a 404 Not Found error. If I try to login through the Python xmlrpclib I got a Protocol error from /RPC2 same 404 Not found error.

(16 Dec '11, 15:15) Phrozen Phrozen's gravatar image

The 404 error is normal, as a browser can not communicate with the API. I can not reproduce the certificate error on my machine. Google Searching for the error seems to suggest this is a problem with Ruby 1.9 and its ability to find the certs. I was unable to locate a solution for windows, nor have access to a windows machine to test.

(16 Dec '11, 19:19) johns ♦♦ johns's gravatar image

Do you know something of Python having 404 error too?

(17 Dec '11, 21:06) Phrozen Phrozen's gravatar image

No, I was doing my testing with python and it was working. Is it possible to try another OS/machine? Can you post the python code you tested too?

(17 Dec '11, 21:23) johns ♦♦ johns's gravatar image

I tried using the code from the webpage:

>>> import xmlrpclib
>>> server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
>>> session_id, account = server.login('widgetsco', 'widgetsrock')

And its working now, maybe the API was offline last time I tried. Anyway, for the Ruby example I'm posting the answer. Thanx for your help.

(17 Dec '11, 23:40) Phrozen Phrozen's gravatar image

With Ruby, to bypass the Certificate error you have to somewhat hack into the API of the xmlrpc/client library. And that is because the API does not provide any simple solution to turn off that warning about the certificate, but here is what I found and it works.

server = XMLRPC::Client.new2("https://api.webfaction.com/")
server.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
server.call("login", "user", "password")

The important line being:

server.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)

That turns off the warning and let you connect to the API via xmlrpc library.

Thanx for the help. Even if I could have used Python, I already had the Ruby code, so this hack is faster and better tan porting the script.

Edit: This works on Ruby 1.9.3p0 and pretty sure it works on most 1.9.x versions.

link

answered 17 Dec '11, 23:44

Phrozen's gravatar image

Phrozen
51129
accept rate: 40%

edited 17 Dec '11, 23:45

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×88
×71
×50
×18

Asked: 16 Dec '11, 15:11

Seen: 1,345 times

Last updated: 17 Dec '11, 23:45

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited