Invalid URI Error when using Mailchimp in Rails

半世苍凉 提交于 2019-12-11 04:58:06

问题


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 I have finished implementing the mailchimp email list code, and when I press submit on my form, I get the following error:

URI::InvalidURIError at /visitors
the scheme https does not accept registry part: us8'.api.mailchimp.com (or bad hostname?)

My debug screen seems to indicate that it's failing at the call

result = mailchimp.lists.subscribe({
  :id => Rails.application.secrets.mailchimp_list_id,
  :email => {:email => self.email},
  :double_optin => false,
  :update_existing => true,
  :send_welcome => true
})

I have my API key and List IDs both hard coded into secrets.yml, so I know they are correct.

Any ideas?

Regards, Jeff


回答1:


The error message indicates that the URL used to contact the Mailchimp server is malformed.

The Gibbon gem constructs the HTTPS request to the Mailchimp server and uses the httparty gem to make the HTTPS request. We can be confident that Gibbon works as expected. You can check the Gibbon issues to confirm; I just did and saw no reported problems like yours.

So we know Gibbon is working, and we can presume the code from the learn-rails tutorial application works (because no one else has reported this problem). So what can be the cause of the problem? My guess is that your API key is incorrect. It may have an extra single quote that does not belong. I'm guessing that something about the API key is preventing Gibbon from forming a correct URL string.

You can diagnose by entering a correctly formatted but wrong API Key. Instead of the URL error should get a response from the Mailchimp server that your API key is not known.



来源:https://stackoverflow.com/questions/23433632/invalid-uri-error-when-using-mailchimp-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!