import requests
# Provide your GitHub credentials
username = "your_username"
old_password = "your_old_password"
new_password = "your_new_password"
# API endpoint for changing password
endpoint = "https://api.github.com/user/update_authenticated"
# Create a session
session = requests.Session()
# Authenticate using the existing password
session.auth = (username, old_password)
# Define the new password
payload = {
"password": new_password
}
# Send a PATCH request to update the password
response = session.patch(endpoint, json=payload)
# Check the response status code
if response.status_code == 200:
print("Password successfully changed.")
else:
print("An error occurred while changing the password.")
print(response.text)