Thursday, 26 August 2021

Change Magento password account from Python script

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

import requests
from bs4 import BeautifulSoup
[...]
s = requests.session()
main_url = 'https://account.magento.com/customer/account/login/'
html_data = s.get(main_url)
form_soup = BeautifulSoup(html_data.content, 'html.parser')
form_key = form_soup.find('input', {'name':'form_key'})['value']
    
login_route = 'https://account.magento.com/customer/account/loginPost/'
login_payload = {
      'form_key': form_key,
      'login[username]': web_user,
      'login[password]': web_pass
}
login_req = s.post(login_route, data=login_payload)
[..]
account_change_password_post = "https://account.magento.com/customer/account/changePasswordPost/"
change_password_payload = {
       'form_key': form_key,
       'current_password': web_pass,
       'password': new_pass,
       'password_confirmation' : new_pass
}
    
change_pass_req = s.post(account_change_password_post, data=change_password_payload)

But it doesn't let me update the password so I was wondering if someone could tell me what it takes to be able to update the password through Python to Magento account?



from Change Magento password account from Python script

No comments:

Post a Comment