- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
01-25-2024 10:34 PM
Hello,
I'm a newbie In Cyberark CCP and I wondering how can I get the credential from CCP with OS username authentication.
I can get the credential by Powershell script like this
$appid = 'My_APP'
$safe = 'My_Safe'
$credtofetch = 'My_Account'
#execute REST API call
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
invoke-restmethod -Credential (get-credential) -uri https://abc.mydomain.com/aimwebservice/api/accounts -method GET -Body @{AppID =
$appid; Safe = $safe; UserName = $credtofetch; Reason = 'Powershell'}But I cannot find the way to get the credential when using python code.
my code always return 403 with error "APPAP133E Failed to verify application authentication data: OSUser \\" \\" is unauthorized"
Python code
import requests
from requests_ntlm import HttpNtlmAuth
import getpass
import ssl
# Replace these values with your API endpoint and Windows domain
certificate_path = 'C:MyClientCert\certificate.pem'
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain(certfile=certificate_path)
api_url = 'https://abc.mydomain.com/AIMWebService/api/Accounts?AppID=my_app&Safe=My_safe&Object=My_Account'
domain = 'mydomain.com'
# Get the current Windows username
windows_username = getpass.getuser()
# Prompt for the Windows password
windows_password = getpass.getpass(f"Enter the password for {windows_username}@{domain}: ")
# Make a request to the API using NTLM authentication
response = requests.get(api_url, auth=HttpNtlmAuth(f'{domain}\\{windows_username}', windows_password),cert=certificate_path, verify=False)
# Check the response
if response.status_code == 200:
print("Successfully authenticated.")
print("Response:")
print(response.text)
else:
print(f"Failed to authenticate. Status code: {response.status_code}")does anyone have succeeded with this aspect can give me your Python code?
01-26-2024 05:57 AM
@Hiep Nguyen? This article should help you resolve your issue
https://community.cyberark.com/s/article/CCP-AIMWebService-Windows-Authentication-not-working
01-28-2024 08:07 PM
Hi @Hiep Nguyen
The error you're encountering indicates an authorisation issue, and it seems to be related to the application authentication. Please verify that you have the necessary permissions to access the specified account in the Safe, and that your application has the required privileges.
Please refer to the link shared by @Vinay Vasanth
The Python script, it looks good to me. There are couple of observations.
1.The requests_ntlm library already handles NTLM authentication, so you don't need to manually construct the authentication string
Change the line,
response = requests.get(api_url, auth=HttpNtlmAuth(f'{domain}\\{windows_username}', windows_password), cert=certificate_path, verify=False)
To
response = requests.get(api_url, auth=HttpNtlmAuth(f'{windows_username}@{domain}', windows_password), cert=(certificate_path, certificate_path), verify=False)
2.It's not recommended to disable SSL verification (verify=False). Instead, provide the path to the CA certificate used by the server
Hope it helps !
01-28-2024 11:22 PM
Hello @Vinay Vasanth . All configurations based on the document have been set already. but it is still the same. and the problem is Python code does not work, but Powershell still works correctly
02-12-2025 11:00 PM
Working Python script without explicitly specifying the username / password for OS Authentication
Note: Ensure that CCP server and the server from where you execute this script are in same domain.
import win32com.client, json
Host = "https://pvwauat.com/AIMWebService/api/Accounts"
AppID = "DiscoveryScanApplication"
Safe = "DiscoveryScanAppWindows"
Folder = "Root"
Object = "Operating System-AD-ERDRSSD40D.COMPANY-HPDRDTAN"
url = Host+'?AppID='+AppID+'&Folder='+Folder+'&safe='+Safe+'&object='+Object
httpsRequest = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
httpsRequest.SetAutoLogonPolicy(0)
httpsRequest.Open('GET', url, False)
httpsRequest.Send()
result = httpsRequest.responseText
# Check the response
if httpsRequest.Status == 200:
print("Successfully authenticated.")
jsonResponse = json.loads(result)
username = jsonResponse.get('UserName')
password = jsonResponse.get('Content')
print("UserName : " + username + " Password : " + password)
else:
print(f"Failed to authenticate. Status code: {httpsRequest.Status}")
02-12-2025 11:01 PM
Working Python script without explicitly specifying the username / password for OS Authentication
Note: Ensure that CCP server and the server from where you execute this script are in same domain.
import win32com.client, json
Host = "https://pvwauat.com/AIMWebService/api/Accounts"
AppID = "DiscoveryScanApplication"
Safe = "DiscoveryScanAppWindows"
Folder = "Root"
Object = "Operating System-AD-ERDRSSD40D.COMPANY-HPDRDTAN"
url = Host+'?AppID='+AppID+'&Folder='+Folder+'&safe='+Safe+'&object='+Object
httpsRequest = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
httpsRequest.SetAutoLogonPolicy(0)
httpsRequest.Open('GET', url, False)
httpsRequest.Send()
result = httpsRequest.responseText
# Check the response
if httpsRequest.Status == 200:
print("Successfully authenticated.")
jsonResponse = json.loads(result)
username = jsonResponse.get('UserName')
password = jsonResponse.get('Content')
print("UserName : " + username + " Password : " + password)
else:
print(f"Failed to authenticate. Status code: {httpsRequest.Status}")
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!

