import requests
# API credentials
API_PUBLIC_KEY = "your_public_key"
API_PRIVATE_KEY = "your_private_key"
BASE_URL = "https://api.pingproxies.com/1.0/public"
# Headers for authentication
headers = {
"X-API-Public-Key": API_PUBLIC_KEY,
"X-API-Private-Key": API_PRIVATE_KEY,
"Content-Type": "application/json"
}
def edit_proxy_user_authentication(proxy_user_id, new_password=None, ip_addresses=None, enable_strict_security=None):
"""
Update a proxy user's authentication settings.
Args:
proxy_user_id: ID of the proxy user to edit
new_password: New password for the proxy user (optional)
ip_addresses: List of IP addresses to whitelist (optional)
enable_strict_security: Boolean to enable/disable strict security (optional)
Returns:
API response or None if the update failed
"""
# Build the request URL
url = f"{BASE_URL}/user/proxy_user/edit/{proxy_user_id}"
# Initialize the payload dictionary - we'll only include fields we want to update
payload = {}
# Add new password if provided
if new_password:
payload["proxy_user_password"] = new_password
# Add IP address authentication if provided
if ip_addresses:
payload["ip_address_authentications"] = ip_addresses
# Set strict security mode if provided
if enable_strict_security is not None:
payload["proxy_user_is_strict_security"] = enable_strict_security
# Make the API request
response = requests.patch(url, headers=headers, json=payload)
# Check if the request was successful
if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code}")
print(response.text)
return None
# Example usage
if __name__ == "__main__":
# Define parameters
PROXY_USER_ID = "marketingteam" # ID of the proxy user to update
NEW_PASSWORD = "SecurePssw0rd123" # New secure password
# List of whitelisted IP addresses for this proxy user
IP_ADDRESSES = [
"192.168.1.100", # Office IP address
"203.0.113.45" # Remote worker IP address
]
# Enable strict security (requires IP authentication)
ENABLE_STRICT_SECURITY = True
# Update the proxy user
result = edit_proxy_user_authentication(
proxy_user_id=PROXY_USER_ID,
new_password=NEW_PASSWORD,
ip_addresses=IP_ADDRESSES,
enable_strict_security=ENABLE_STRICT_SECURITY
)
if result:
print("Proxy user authentication updated successfully")
print(f"Edited proxy user: {result['edited'][0]}")
else:
print("Failed to update proxy user authentication")
# Note: You can modify this function to update other proxy user settings:
# - proxy_user_is_service_restricted: Restrict the user to specific services
# - restricted_service_ids: List of service IDs when service restriction is enabled
# - proxy_user_metadata: Customer metadata for organization and tracking
# - proxy_user_residential_bytes_limit: Set bandwidth limits for residential proxies