1

I'm having some trouble authenticating myself into the PJ website using the Python requests module. My code is as follows:

import requests 

with requests.Session() as s:
    s.auth = ("my_email", "my_password")
    r = s.get( "https://www.example.com/")

However, I receive a response which indicates that I haven't logged in. Is it simply impossible to do this? Am I missing something (e.g. CSRF token)?

EDIT: I did some poking around to see what happens when I manually log in. You can see a screengrab of the request my browser sends here: PJ Login Request

3
  • 2
    You probably need to POST to a login endpoint - I'd be surprised if papajohns just used basic http authentication... (which means you need to look at the page source - identify the form, the target url and construct the appropriate request to emulate the login) Commented Sep 16, 2017 at 11:57
  • @JonClements The image in my edit shows the form data (i.e. target url, user, pass), however, I am little lost in figuring out what type of authentication to use. Any advice? Commented Sep 16, 2017 at 12:20
  • You generally don't use any... you make a suitable POST request with your username/password to the right place with a requests.Session() as you are, then you'll probably get a cookie back, so that re-using the session to make further requests means you're already logged in... Commented Sep 16, 2017 at 12:22

2 Answers 2

1

Figured it out, following Jon's guidance:

with requests.Session() as s:
    payload = {'user':'my_email','pass':'my_password', 'target':'/order/menu'}
    r = s.post( "https://www.example.com/order/signin", data=payload)

I had already figured out the correct payload from the request (using the screengrab in my edit above), but I was sending it to the wrong location (i.e. the home page instead of the user login page).

Sign up to request clarification or add additional context in comments.

Comments

0

Try with Post Method which is not sent in plaintext if using http.

With https BOTH GET and POST are sent securely and not in plaintext.

import requests 

with requests.Session() as s:
    s.auth = ("my_email", "my_password")
    r = s.post( "https://www.papajohns.com/")


>>> r
>>> <Response [200]>

2 Comments

Tried this, but unfortunately, it gives me the same result as using a GET request.
A get method over https is not sent in plaintext either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.