Skip to main content

Steps on how to execute the below Python script: Do we need to install any libraries on the server? as the below script is providing an output outside of the A360

 

import datetime
import base64
import hmac
import hashlib
import time
 
 
def hmac_sha256(message, key):
    key = bytes(key, 'UTF-8')
    message = bytes(message, 'UTF-8')
    h = hmac.new(key, message, hashlib.sha256)
    return base64.b64encode(h.digest()).decode()
 
def authorization(strAKID, strAKSecret):
    
    strDateNow = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
    print(f"date is: {strDateNow}")
    strSignContent = "date: {}".format(strDateNow)
    #Compute signature, get authorization
    strSignature = hmac_sha256(strSignContent, strAKSecret)
    print(f"signature is: {strSignature}")
    strAuthorization = '''hmac username="{}", algorithm="hmac-sha256", headers="date", signature="{}"'''.format(strAKID, strSignature)
if __name__ == '__main__':

    strAKID = "e2c5b464-5361-40f2-9c8e-bc04962db1a7"
    strAKSecret = "I5lGga3vfFW8Nf9HbRHuUnROcga0SnpP"
    authorization(strAKID, strAKSecret)

Hi shakir_mohammed, 

 

can you share the screenshot of the error you received while running the same code in AA?


Getting Above Error

 


It just shows bot error

 


You’re using a hacky way of calling a function with the if __name__ == “__main__”. Converting that entry point to a function causes your script to work, or at least it returns null.

We need to know what parameters you’re trying to send to the function, though, because the assumed main() function doesn’t seem to need any parameters -- they’re hard-coded. Is that where your list variable entries are supposed to be?

To troubleshoot Python problems like this, go to the C:\ProgramData\AutomationAnywhere\BotRunner\Logs folder (or wherever your logs are stored) and open your Bot_Launcher_YOURNAME.log file. It will give you the output from the Python engine as to what the problem is.


Hi Shakir,

As Aaron mentioned, please look into the folder in the local drive to get more details about the issue.

Another way to use the Python command package is to use the execute script instead of the execute function. 


Hi @patelmaulesh , I tried executing the script, but the output shows as true.


Hi @Aaron.Gleason, yes, I am trying to pass the arguments to call the function. “hmac_sha256” and “authorization” by passing the value in the list.


Then you need to reformat your function. Don’t use the __name__ construct. Make it a real function with a real variable as a parameter, such as:

def main(listParameter):

Then you have a defined entry point that you can pass parameters to.


I have tried the approach and printed the result in a text file, so this is working.


Reply