cancel
Showing results for 
Search instead for 
Did you mean: 

Logging in to Magento account from Python script.

Logging in to Magento account from Python script.

Hello,

 

I hope I'm posting my question in the right section.

 

I'm trying to login to Magento account from Python script using requests module, the relevant code I made looks as below:

 

s = requests.session()
main_url = '<redacted.tld>/en/index.html'
html_data = s.get('https://'+main_url, headers=headers, timeout=(30, 30), verify=dst_verify_ssl) web_user = 'test@test.com' web_pass = '123test321' form_key = soup.find('input', {'name':'form_key'})['value'] l_url = 'https://<redacted.tld>/'
l_route = 'en/customer/account/loginPost/'
login_payload = { 'form_key':form_key, 'login[username]':web_user, 'login[password]':web_pass } login_req = s.post(l_url + l_route, headers=headers, data=login_payload)

But it's not getting me logged in so I was wondering if someone could tell me what does it take to login via Python to the Magento account?

 

Thanks upfront.

 

 

 

4 REPLIES 4

Re: Logging in to Magento account from Python script.

Hi,

 

please try to use Token-based authentication instead of sending requests to loginPost controller. This should be helpful for you: 

 

https://devdocs.magento.com/guides/v2.3/get-started/authentication/gs-authentication-token.html

 

Regards,

Marcin

Re: Logging in to Magento account from Python script.

Token-based authentication isn't available for me, therefore, the only way would be to login via a POST request.

 

I'm not sure what info needs to be submitted in the POST request and I've found no documentation so far, could you please point me into the right direction?

Re: Logging in to Magento account from Python script.

I'm either missing some header when sending POST to Magento or...., I've included about everything Chrome DOM inspector captured.

 

I didn't found related documentation either, for instance, I tried to authenticate via POST to WordPress, took just a few minutes.

 

There must be something I'm missing with Magento but I ran out of ideas.

Re: Logging in to Magento account from Python script.

Could you solve this finally? I'm stuck at the same point..