<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Looking for Python example to get authorization token with API in PAM Self-Hosted Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362210#M51007</link>
    <description>&lt;P&gt;import requests&lt;/P&gt;&lt;P&gt;import time&lt;/P&gt;&lt;P&gt;import getpass&lt;/P&gt;&lt;P&gt;import base64&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Enter login Credentials to authenticate&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;username= getpass.getpass("Enter your vault username:")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;password = base64.b64encode(getpass.getpass("Enter vault Password:"))&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print ('ERROR', err)&lt;/P&gt;&lt;P&gt;url="https://PVWA/PasswordVault/WebServices/auth/Cyberark/CyberArkAuthenticationService.svc/Logon"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Cache-Control': 'max-age=300'}&lt;/P&gt;&lt;P&gt;data = '{ "username":"'+username+'","password":"'+base64.b64decode(password)+'",&amp;nbsp;&amp;nbsp;"useRadiusAuthentication":"false",&amp;nbsp;"connectionNumber":"1"}'&lt;/P&gt;&lt;P&gt;response = requests.request("POST",url, headers=headers, data=data, verify=False)&lt;/P&gt;&lt;P&gt;output_response=response.json()&lt;/P&gt;&lt;P&gt;auth_token=output_response['CyberArkLogonResult']&lt;/P&gt;&lt;P&gt;print auth_token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Enter Account Details&amp;nbsp;&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;username= getpass.getpass("Enter serivce Account name:")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;Password= getpass.getpass("Enter Serivce Account Password:")&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print ('ERROR', err)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;url = "https://PVWA/PasswordVault/WebServices/PIMServices.svc/Account"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Authorization':auth_token}&lt;/P&gt;&lt;P&gt;data = '{"account" : { "safe":"XXXXXXXX","platformID":"XXXXXXXX","address":"XXXXXX","username":"'+username+'","password":"'+Password+'","disableAutoMgmt":"false","Port":"XXXXX","Database":"XXXXX" }}'&lt;/P&gt;&lt;P&gt;response = requests.request("POST",url, headers=headers, data=data, verify=False)&lt;/P&gt;&lt;P&gt;time.sleep(1)&lt;/P&gt;&lt;P&gt;#print (response.text)&lt;/P&gt;&lt;P&gt;statusCode=response.status_code&lt;/P&gt;&lt;P&gt;if statusCode == 201:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Account Added succesfully:{}".format(statusCode)&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print " Account Failed to Add: {}".format(statusCode)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# logout of the vault&amp;nbsp;&lt;/P&gt;&lt;P&gt;url="https://XXXXXXXX/PasswordVault/WebServices/auth/Shared/RestfulAuthenticationService.svc/Logoff"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Authorization':auth_token}&lt;/P&gt;&lt;P&gt;response = requests.request("POST", url, headers=headers, verify=False)&lt;/P&gt;&lt;P&gt;time.sleep(1)&lt;/P&gt;&lt;P&gt;logoff_response=response.status_code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if logoff_response == 200:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Session terminated with status_code: {}".format(logoff_response)&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Session is NOT terminated and default timeout is 30 minutes. status_code: {}".format(logoff_response)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2020 01:22:54 GMT</pubDate>
    <dc:creator>Anurag_Yelala</dc:creator>
    <dc:date>2020-01-28T01:22:54Z</dc:date>
    <item>
      <title>Looking for Python example to get authorization token with API</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362209#M51006</link>
      <description>&lt;P&gt;I took the Python - Requests code from Postman and ran it in Python IDE.  I can get the token with the payload string from Postman with the actual username and password.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;payload = "{\n\t\"username\": \"APIuser\",\n\t\"password\": \"APIpw\",\n\t\"connectionNumber\": \"1\"\n}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have not been able to find the right syntax to be able to pass in the above example APIuser and APIpw as variables.  If I do a print on payload, I see the variable values are being passed, however I am receiving the below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;b'\xc3\xaf\xc2\xbb\xc2\xbf&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;\r\n&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;\r\n&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;\r\n&amp;nbsp;&amp;lt;head&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;Request Error&amp;lt;/title&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;style&amp;gt;BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}&amp;lt;/style&amp;gt;\r\n&amp;nbsp;&amp;lt;/head&amp;gt;\r\n&amp;nbsp;&amp;lt;body&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div id="content"&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p class="heading1"&amp;gt;Request Error&amp;lt;/p&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;p&amp;gt;The server encountered an error processing the request. See server logs for more details.&amp;lt;/p&amp;gt;\r\n&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;\r\n&amp;nbsp;&amp;lt;/body&amp;gt;\r\n&amp;lt;/html&amp;gt;'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please share any working examples&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shawn&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 22:10:39 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362209#M51006</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2020-01-27T22:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for Python example to get authorization token with API</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362210#M51007</link>
      <description>&lt;P&gt;import requests&lt;/P&gt;&lt;P&gt;import time&lt;/P&gt;&lt;P&gt;import getpass&lt;/P&gt;&lt;P&gt;import base64&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Enter login Credentials to authenticate&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;username= getpass.getpass("Enter your vault username:")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;password = base64.b64encode(getpass.getpass("Enter vault Password:"))&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print ('ERROR', err)&lt;/P&gt;&lt;P&gt;url="https://PVWA/PasswordVault/WebServices/auth/Cyberark/CyberArkAuthenticationService.svc/Logon"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Cache-Control': 'max-age=300'}&lt;/P&gt;&lt;P&gt;data = '{ "username":"'+username+'","password":"'+base64.b64decode(password)+'",&amp;nbsp;&amp;nbsp;"useRadiusAuthentication":"false",&amp;nbsp;"connectionNumber":"1"}'&lt;/P&gt;&lt;P&gt;response = requests.request("POST",url, headers=headers, data=data, verify=False)&lt;/P&gt;&lt;P&gt;output_response=response.json()&lt;/P&gt;&lt;P&gt;auth_token=output_response['CyberArkLogonResult']&lt;/P&gt;&lt;P&gt;print auth_token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Enter Account Details&amp;nbsp;&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;username= getpass.getpass("Enter serivce Account name:")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;Password= getpass.getpass("Enter Serivce Account Password:")&lt;/P&gt;&lt;P&gt;except:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print ('ERROR', err)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;url = "https://PVWA/PasswordVault/WebServices/PIMServices.svc/Account"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Authorization':auth_token}&lt;/P&gt;&lt;P&gt;data = '{"account" : { "safe":"XXXXXXXX","platformID":"XXXXXXXX","address":"XXXXXX","username":"'+username+'","password":"'+Password+'","disableAutoMgmt":"false","Port":"XXXXX","Database":"XXXXX" }}'&lt;/P&gt;&lt;P&gt;response = requests.request("POST",url, headers=headers, data=data, verify=False)&lt;/P&gt;&lt;P&gt;time.sleep(1)&lt;/P&gt;&lt;P&gt;#print (response.text)&lt;/P&gt;&lt;P&gt;statusCode=response.status_code&lt;/P&gt;&lt;P&gt;if statusCode == 201:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Account Added succesfully:{}".format(statusCode)&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print " Account Failed to Add: {}".format(statusCode)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# logout of the vault&amp;nbsp;&lt;/P&gt;&lt;P&gt;url="https://XXXXXXXX/PasswordVault/WebServices/auth/Shared/RestfulAuthenticationService.svc/Logoff"&lt;/P&gt;&lt;P&gt;headers = { 'Content-Type': 'application/json','Authorization':auth_token}&lt;/P&gt;&lt;P&gt;response = requests.request("POST", url, headers=headers, verify=False)&lt;/P&gt;&lt;P&gt;time.sleep(1)&lt;/P&gt;&lt;P&gt;logoff_response=response.status_code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if logoff_response == 200:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Session terminated with status_code: {}".format(logoff_response)&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;print "Session is NOT terminated and default timeout is 30 minutes. status_code: {}".format(logoff_response)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 01:22:54 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362210#M51007</guid>
      <dc:creator>Anurag_Yelala</dc:creator>
      <dc:date>2020-01-28T01:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for Python example to get authorization token with API</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362211#M51008</link>
      <description>&lt;P&gt;Rag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!  This resolved my issue.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2020 15:19:37 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362211#M51008</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2020-01-28T15:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for Python example to get authorization token with API</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362212#M51009</link>
      <description>&lt;P&gt;@Anurag .​&amp;nbsp; Thank You! This Helps.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jan 2021 07:09:58 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/looking-for-python-example-to-get-authorization-token-with-api/m-p/1362212#M51009</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-01-17T07:09:58Z</dc:date>
    </item>
  </channel>
</rss>

