1

I'm getting an SSL Certificate error when I try to access a web server using HTTParty. This is the error I got originally.

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I tried to correct his by updating default options. The code is below.

class Coursera
    include HTTParty
    base_uri 'https://api.coursera.org/api/catalog.v1/courses'
    default_params fields: "smallIcon,shortDescription", q: "search"
    format :json
    default_options.update(verify: false)

    def self.for term
      get("", query: { query: term})["elements"]
    end
end

However, this resulted in another error, which is confounding me.

syntax error, unexpected tIDENTIFIER, expecting keyword_end default_options.update(verify: false)

Can someone explain why this error is occurring and how I can bypass the SSL in order to obtain the results of the query?

1 Answers1

0

You're getting syntax error, unexpected tIDENTIFIER, expecting keyword_end default_options.update(verify: false) because of this line

HTTParty.get(get("", query: { query: term})["elements"])

There is a missing bracket at the end. Actually, you don't need to call get on HTTParty. Replace

HTTParty.get(get("", query: { query: term})["elements"])

with

get("",query: { query: term})["elements"])

Compare your file with https://github.com/jhu-ep-coursera/fullstack-course1-module3/blob/master/app/models/coursera.rb

Back to the SSl error now.

From https://gist.github.com/mislav/5026283

The reason why you might get certificate errors in Ruby 2.0 when talking > HTTPS is because there isn't a default certificate bundle that OpenSSL (which was used when building Ruby) trusts.

Instead of disabling SSL, you can get around the error by installing the certificate.

The gist also contains information on how to install the certificate bundle manually.

Hope this helps!

Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44