Error with Carrierwave and FFaker::Avatar.image

Error with Carrierwave and FFaker::Avatar.image

If you’re facing this error:

could not download file: SSL_connect returned=1 errno=0 state=error: certificate verify failed

It’s because the FFaker::Avatar.image remote image returns a https image.

This is for example how it looks my code:

post :create, { format: :json, version: 1, user: {
  avatar_url: FFaker::Avatar.image,
  username: 'username'
}}

In order to fix the problem you can create a new initializer and place the following code:

config/initializers/disable_ssl_for_development_and_test.rb

  if Rails.env.development? || Rails.env.test?
    # in order to avoid the error:
    # Fix SSL_connect returned=1 errno=0 state=SSLv3
    # read server certificate B: certificate verify failed
    # when using FFaker::Avatar.image
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
  end

That’s it or in case you don’t like this workaround instead of using remote images you can open local images:

post :create, { format: :json, version: 1, user: {
  avatar: File.open(File.join(Rails.root, "spec/fixtures/images/document_example.png")),
  username: 'username'
}}

There you go.

Thanks for reading

H.

No Comments

Post A Comment