0

I am trying to log into mailchimp at

https://login.mailchimp.com/

using this code

REQUEST_URL = "https://login.mailchimp.com"
payload = {'username': '...','password': '...'}

with requests.Session() as session:
    post = session.post(REQUEST_URL, data=payload)
    print(post.text)

When I display the output text in a simple html viewer I see this:

this

Which leads me to believe that the username is being posted correctly but the password is not. When I inspect the login webpage I see this for the password field:

this

It looks like I am doing everything correctly. But when I try to request a new url like, https://us12.admin.mailchimp.com/audience/ and I view the resulting html, it's still the login page. Why is it failing to log in?

EDIT... I added these lines of code:

import logging
logging.basicConfig(level=logging.DEBUG)
...
print(session.cookies.get_dict())

And this is my output:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): login.mailchimp.com:443 DEBUG:urllib3.connectionpool:https://login.mailchimp.com:443 "POST / HTTP/1.1" 200 9948 {'PHPSESSDATA': '3fb1877dc92d79879494987b07030b36dcc1f83d%3A1560273156%3AeNoDAAAAAAE%3D', 'QA': '0', '_mcid': '1.94e032f7d29eaf0a3f717796cb7f3785', 'PHPSESSID': 'fe08be42828591d939099f0793f115aa', '_AVESTA_ENVIRONMENT': 'prod'}

EDIT 2:

I tried passing the cookies from the login like this:

with requests.Session() as session:
    post = session.post(REQUEST_URL, data=payload)
    r = session.get(NEXT_URL,cookies=session.cookies.get_dict())
    print(r.text)

and also like this:

with requests.Session() as session:
    post = session.post(REQUEST_URL, data=payload)
    r = session.get(NEXT_URL,cookies=session.cookies)
    print(r.text)

But neither worked. I tried getting the cookies from my browser from this area

a

and plugged them into a dictionary and tried using them like this:

cookys_from_browser={'MC_PLUMS_LOGIN': '...','MC_USER_INFO': '...','MC_USER_PROFILE': '...','MUID': '...',.....}

with requests.Session() as session:
    post = session.post(REQUEST_URL, data=payload,cookies=cookys_from_browser)
    r = session.get(NEXT_URL,cookies=cookys_from_browser)

But that also did not work.

Josh Flori
  • 104
  • 11
  • 1
    Logging in probably assigns you some cookie(s) in the browser. If you don't make the subsequent request with this cookie(s), the site will not believe that you have been authenticated. – JacobIRR Jun 11 '19 at 16:34
  • So I need to get cookies from chrome and insert them into my post request? Or get cookies from my post request when trying to access the next page? That doesn't seem right since this [this](https://stackoverflow.com/questions/31554771/how-to-use-cookies-in-python-requests) indicates that shouldn't be true – Josh Flori Jun 11 '19 at 16:43
  • log your response and its cookies to see if you have a cookie with a name that suggest auth. Once you add that to your question, it should be a little easier to find out what the next steps are. – JacobIRR Jun 11 '19 at 16:45
  • I don't know if I did it right but I updated my question as best I could – Josh Flori Jun 11 '19 at 16:50
  • ok cool, now at this point, you can try attaching all those cookies to your request to `https://us12.admin.mailchimp.com/audience/` to see if that helps. If not. I'd try logging in via the browser, then after you're logged in, look at the cookies in the inspector to see if you are missing any. – JacobIRR Jun 11 '19 at 16:57
  • The first method didn't work. I also tried getting from the browser and that didn't work either but I definitely saw more fields. I updated my question if you want to take a look. Its rather frustrating because I am able to log into other password protected sites but am struggling with this one. thanks – Josh Flori Jun 11 '19 at 18:19

0 Answers0