API attempt from Heroku results in DNS error 'SocketError: Hostname not known'

958 Views Asked by At

I'm running an application on Heroku that attempts to connect to MailChimp using the Gibbon gem (to add an email address to a mailing list). The API connection fails. The Heroku error logs show:

SocketError: getaddrinfo: Name or service not known

I saw a blog post (thanks Mike Subelsky) that recommends adding require 'resolv-replace.rb' to the application in a config/initializer/requires.rb file, so I tried that. Now the Heroku error logs show:

SocketError: Hostname not known: 8c7d675bb0b8.api.mailchimp.com

I'm not sure where the strange hostname comes from. The host "api.mailchimp.com" exists but "8c7d675bb0b8.api.mailchimp.com" doesn't exist.

The application works in development on my local machine. And other applications on Heroku that use the same code also work without a problem. What's going on and how can I fix it?

1

There are 1 best solutions below

0
On

I had this same issue and finally found what was causing it. When I set my api key on Heroku, I was missing the -us4 on the end. The Mailchimp api library splits on the "-" and prepends the us4 to build the api url.