我正在尝试登录网站,但我的环境变量没有以必要的形式正确插入。我正在使用 Figaro,我的环境变量安全地存储在config/application.yml
. 我可以确认两件事...
- 硬编码我的实际电子邮件和密码时,我能够成功登录
在 Rails 控制台中测试时,我的环境变量正确返回(例如 ENV["WHATEVER"] 返回正确的值)
# app/helpers/scrape_wf.rb require 'mechanize' agent = Mechanize.new page = agent.get('https://www.wealthfront.com/login') login_form = page.forms.first # LOG IN UNSUCCESSFUL login_form.email = ENV["WF_EMAIL"] login_form.password = ENV["WF_PASSWORD"] home_page = login_form.submit puts page.title # => Log In to Wealthfront puts home_page.title # => Log In to Wealthfront # LOG IN SUCCESSFUL login_form.email = "my_harcoded_email" login_form.password = "my_harcoded_password" home_page = login_form.submit puts page.title # => Log In to Wealthfront puts home_page.title # => Wealthfront
在控制台中......
rails c
Loading development environment (Rails 4.2.4)
[1] pry(main)> ENV["WF_EMAIL"]
=> "my_harcoded_email"
[2] pry(main)> ENV["WF_PASSWORD"]
=> "my_harcoded_password"
我究竟做错了什么...?