Edit Proxy User Authentication by adding IP Authentication and Changing Password
Learn how to modify a proxy user’s authentication by adding IP addresses and updating the password with the Ping Proxies API.
This example demonstrates how to update a proxy user’s authentication settings using the Ping Proxies API. Specifically, we’ll show how to:
Add IP address authentication to an existing proxy user
Change the proxy user’s password
Enable strict security mode
These operations are common when you need to enhance security for your proxy users or update their authentication credentials.
import requests# API credentialsAPI_PUBLIC_KEY ="your_public_key"API_PRIVATE_KEY ="your_private_key"BASE_URL ="https://api.pingproxies.com/1.0/public"# Headers for authenticationheaders ={"X-API-Public-Key": API_PUBLIC_KEY,"X-API-Private-Key": API_PRIVATE_KEY,"Content-Type":"application/json"}defedit_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 orNoneif 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 providedif new_password: payload["proxy_user_password"]= new_password# Add IP address authentication if providedif ip_addresses: payload["ip_address_authentications"]= ip_addresses# Set strict security mode if providedif enable_strict_security isnotNone: 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 successfulif response.status_code ==200:return response.json()else:print(f"Error: {response.status_code}")print(response.text)returnNone# Example usageif __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