I am trying to get all email address of subscribers from a specific list (which has a unique listid) in Mailchimp.
If I print body, the output is in json format as below.
I'm trying to convert the json to dictionary.
After it was converted to dictionary, I would like to get all the email_address.
After I get all the email address, I would like to encrypt it using md5.
However I run into error 'TypeError: expected string or buffer'.
I am really new to python, try to solve it but could not. Thanks for looking at my question.
/* My python code */
params = {
'apikey': 'xyz',
'listId': 'abc' }
config = MailChimpConfig()
endpoint = "https://us5.api.mailchimp.com/3.0/lists/'listId'/members?
apikey='apikey'&status=subscribed"
while True:
response = requests.get(endpoint, auth=('apikey', config.apikey),
params=params, verify=False)
try:
response.raise_for_status()
body = response.json
dict = json.loads(body)
print(dict.members[0].email_address)
break
except requests.exceptions.HTTPError as err:
print "Error: {} {}".format(str(response.status_code), err)
print json.dumps(response.json(), indent=4)
break
except ValueError:
print "Cannot decode json, got %s" % response.text
break
/* end of my python code */
/* If I print body, the output is in json format as below:*/
{
- members: [
- {
id: "",
email_address: "x@hotmail.com",
etc:""
},
- {
id: "",
email_address: "y@gmail.com",
etc:""
}
/* end of json format */