问题
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