Yann Kerhervé  committed 90f2b6a

Fix "wrong datacenter" issues in api keys

This issue arise when in the same process two apikeys with different
datacenters are used. The ROOT global variable is tainted by the first
datacenter and all the requests for the second datacenter go instead to
the first one.

  • Participants
  • Parent commits ad00351

Comments (0)

Files changed (1)


         dc = 'us1'
         if apikey.find('-'):
             dc = apikey.split('-')[1]
-        global ROOT
-        ROOT = ROOT.replace('https://api.', 'https://'+dc+'.api.')
+        self.root = ROOT.replace('https://api.', 'https://'+dc+'.api.')
         self.folders = Folders(self)
         self.templates = Templates(self)
         if params is None: params = {}
         params['apikey'] = self.apikey
         params = json.dumps(params)
-        self.log('POST to %s%s.json: %s' % (ROOT, url, params))
+        self.log('POST to %s%s.json: %s' % (self.root, url, params))
         start = time.time()
-        r ='%s%s.json' % (ROOT, url), data=params, headers={'content-type': 'application/json', 'user-agent': 'MailChimp-Python/2.0.7'})
+        r ='%s%s.json' % (self.root, url), data=params, headers={'content-type': 'application/json', 'user-agent': 'MailChimp-Python/2.0.7'})
             remote_addr = r.raw._original_response.fp._sock.getpeername() # grab the remote_addr before grabbing the text since the socket will go away