Hi,

I receive this error when I introduce the API key froom my mailchimp account in mailchimp module configuration page. ---> Could not connect to Mailchimp

in watchdog the details says: MCAPI Error: Could not connect to Mailchimp

In my local version of the site it does not happen, so it looks like a server problem, but how can I be sure of that? Any suggestions?¿ Anyone with the same problem??

Thanks!

Files: 
CommentFileSizeAuthor
#7 MCAPI.class_.txt141.85 KBiwebconsultant

Comments

Category:bug» support
Status:Active» Postponed (maintainer needs more info)

The error should only be logged when the service cannot be reached. Were the MailChimp lists available after the API key was input?

No, I don't have any lists available after this error. I think it should be a problem with the server, maybe a closed port which is necessary to reach mailchimp. I am waiting the response from the technical service......

Did you ever get past this? I've just updated from 2.5 to 2.6 and now cannot connect.

Could roll back, but have strange behaviour with user settings not sticking until Cron is run.

I get the same error on both local & a live site.

All I see when in settings is 1 field for the API key, which when I enter it I get the following messages,

Could not connect to Mailchimp
You do not have any valid MailChimp mailing lists.

I have tried this on a fresh install of drupal with no other modules too with the same results.

The mailchimp account does have a list created. Or should I be creating a list within Drupal?
Apologies if I am doing something simple wrong, but I have never used mailchimp before & can't find a solution anywhere.

Thanks.

Turns out it was the server firewall blocking the connection to the mailchimp API.

I assumed I was doing something incorrect as it wasn't working on my local server either, and as I had never used the module before I didn't know if it wasn't working due to user error (i.e. Me). But when I tested it on a different live server it worked fine.

In case others come across the same issue here are the domains you need to allow in your firewall rules.

us1.api.mailchimp.com
us2.api.mailchimp.com

You will probably need the actual ip addresses to add them to your firewall rules, so ping the above urls and you will get the current ip address. The IP addresses may change from time to time, so if the connection fails after a sucessful installation ping them again and get the new ip address.

Status:Postponed (maintainer needs more info)» Closed (works as designed)

@sugarbase Thanks for the update.

StatusFileSize
new141.85 KB

I replaced the MCAPI.class.php file in the Drupal 6.2 versions with the latest one from Drupal 7 and it works. Rename the attached text file to php and use it.

replacing the MCAPI.class.php file with the 7.x version (post #7), also fixed the issue for me

I replaced the file but mailchimp stop fetching list from mailchimp website, couldnt understand why.
Still getting "could not connect to mailchimp".
Please help me
thanks

This will be solve by editing mailchimp 1.2v, there is a mistake in MCAPI class file,
if ($this->secure){
try {
$sock = @fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
if(!$sock){
throw new Exception('Could not connect to Mailchimp');}
} catch (Exception $e) {
drupal_set_message($e->getMessage(), 'warning', $repeat=false);
watchdog('mailchimp', 'MCAPI Error: %errormsg', array('%errormsg' => $e->getMessage()), WATCHDOG_ERROR);
}
} else {
try {
$sock = @fsockopen("ssl://".$host, 443, $errno, $errstr, 30); // This is the mistake which calling ssl in both if and else, fix by replacing following line //
$sock = @fsockopen($host, 80, $errno, $errstr, 30);

if(!$sock){
throw new Exception('Could not connect to Mailchimp');}
} catch (Exception $e) {
drupal_set_message($e->getMessage(), 'warning', $repeat=false);
watchdog('mailchimp', 'MCAPI Error: %errormsg', array('%errormsg' => $e->getMessage()), WATCHDOG_ERROR);
}
}

Thanks Hammad, your solution worked for me (MailChimp module 6.x-2.6)

Chris

Category:support» bug
Status:Closed (works as designed)» Active

If there is an error in the class file, then how can we say "works as designed?" The error needs to be fixed and a new release rolled out.

And, yes, pulling down the 7.x class file seems to get me farther along.

Priority:Normal» Major

I had a similar issue with Mailchimp not working on a local MAMP installation. I was able to narrow the issue down to mailchimp.inc. This is where the MCAPI class is being extended and the callServer method is being overridden. It is using drupal_http_request to return the response. Where as MCAPI is using fsockopen. I was able to solve my issue by deleting the entire mailchimp.inc file. And replacing line 201 in mailchimp.module.

Replace this:

<?php
    $q
= new Mailchimp(variable_get('mailchimp_api_key', ''));
?>

With this:

<?php
  $q
= new MCAPI(variable_get('mailchimp_api_key', ''));
?>

I applied the patch suggested in #14 above to a Drupal 7.19, MailChimp 7.x-2.9, MCAPI 1.3 install running on LAMP and the existing lists are now available. This is a working site that is being upgraded from Drupal 6.9 and MailChimp 6.x-2.4. FWIW the MailChimp account API key was-and-is on data center us2.

Status:Active» Closed (cannot reproduce)

Folks, this thread is completely unfocused and touching on different versions of the module and different issues. If there is a specific issue with an specific version of the module, lets discuss and resolve. The 6.x and 7.x have a completely different feature set, code base, and architecture, so please don't mingle issues across them. @bentekwork, your idea is completely bypassing the module design. If you can't connect, the goal should be figure out why.

This thread started with some folks on 6.x having issues connecting to the MCAPI. I'm going to close this, but if that's still an active issue, then consider reopening with specifics. In general, we're not maintaining the 6.x version any longer and only applying critical bugs or security patches.