0

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)

I'm working through the railsapps.org book on learning rails and am stuck at "Spreadsheet Connection". I have the code exactly as the book spells out, and I have set up an application specific password for Google Drive and tested it. My code looks like the following:

def update_spreadsheet
connection = GoogleDrive.login(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password)
ss = connection.spreadsheet_by_title('Learn-Rails-Example')
if ss.nil?
  ss = connection.create_spreadsheet('Learn-Rails-Example')
end

My secrets.yml file contains the following:

development:
email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>

mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>

and I have my .bashrc file configured correctly per the tutorial.

When I enter the contact form info and press 'submit', I get the following error:

GoogleDrive::AuthenticationError at /contacts
Authentication failed for : Response code 403 for post https://www.google.com/accounts/ClientLogin: Error=BadAuthentication

If I go up and hard code the login and app-specific password in place of Rails.application.secrets.email_provider_username and Rails.application.secrets.email_provider_password it works just fine. As a newbie, I'm unable to follow the code to understand where or how Rails.application.secrets.email_provider_username gets pointed to my .bashrc settings.

Any help is greatly appreciated.

Regards, Jeff

Daniel Kehoe
  • 10,952
  • 6
  • 63
  • 82
trick420
  • 237
  • 3
  • 9
  • Possible problem: Your password contains punctuation characters. – Daniel Kehoe May 01 '14 at 19:29
  • Your .bashrc settings create a Unix environment variable. The variable `ENV["GMAIL_USERNAME"]` obtains the Unix environment variable from the Unix environment. It's just magic :-) which means you'd have to delve deep into very technical territory to learn how it works. – Daniel Kehoe May 01 '14 at 19:34

4 Answers4

0

If your Gmail password contains punctuation characters such as ! and @, surround the password with single quotes before setting the Unix environment variable, like this:

export GMAIL_PASSWORD="'my@#$%&!password'"
Daniel Kehoe
  • 10,952
  • 6
  • 63
  • 82
  • That's not the problem The password (application specific) is all lower case letters. I tried with and without single quotes. It makes no difference. I get the same error. I can hand stuff the address and password into secrets.yml as well and it works. – trick420 May 01 '14 at 20:09
  • It's likely you have a problem with setting Unix environment variables. It's an issue with your system configuration, not Rails or the learn-rails app. Try http://serverfault.com/ for help. – Daniel Kehoe May 01 '14 at 21:08
0

I had the same issue following the tutorial as well. Hardcoded the username and pw as you have done and it worked. I fixed it by putting the bunch of exports in my .bash_profile instead of .bashrc. Don't forget to restart your bash so that the updated environment is loaded.

stonefruit
  • 195
  • 1
  • 10
0

I also ran into the same problem where hard coding works but env variables do not. I tried putting the exports in .bash_profile and .bashrc too.

What worked for me was to add the exports to my .profile.

Running mavericks 10.9.4

ecoding5
  • 404
  • 6
  • 19
-1

I was able to get around this error by removing some stray RVM commands in the .bashrc file. My .bash_profile file is completely blank now and my .bashrc only 6 exports commands.