Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Python lacks POST request example #21

Open
Hendler opened this issue Oct 20, 2015 · 2 comments
Open

Python lacks POST request example #21

Hendler opened this issue Oct 20, 2015 · 2 comments

Comments

@Hendler
Copy link

Hendler commented Oct 20, 2015

e.g. Maybe one for adding members:

mailchimp_api_root = "https://" + shard + ".api.mailchimp.com/3.0/"
endpoint = mailchimp_api_root + "lists/" + mailchimp_list_id + "/members/"
response = requests.post(endpoint, auth=('apikey', mailchimp_api_key), json=payload, verify=False)
@dimmg
Copy link

dimmg commented Feb 4, 2016

also you should json.dumps(...) the payload you are sending in the data, otherwise it'll result in a JSON Parse Error.

payload = json.dumps({"email_address": email, "status": "subscribed"})
response = requests.post(endpoint, auth=('apikey', mailchimp_api_key), data=payload)

@delink
Copy link

delink commented May 27, 2017

That's not true, @dimmg . If you use the "json" attribute instead of the "data" attribute, it will do the json.dumps() for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants