Skip to main content
Cadet | Tier 2
April 17, 2024
Solved

Executing Python script but getting BOT Error

  • April 17, 2024
  • 9 replies
  • 1369 views

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)

Best answer by Aaron.Gleason

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.

9 replies

Automation Anywhere Team
April 17, 2024

Hi shakir_mohammed, 

 

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

Cadet | Tier 2
April 17, 2024

Getting Above Error

 

Cadet | Tier 2
April 17, 2024

It just shows bot error

 

Aaron.Gleason
Automation Anywhere Team
Automation Anywhere Team
April 17, 2024

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.

Automation Anywhere Team
April 17, 2024

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. 

Cadet | Tier 2
April 18, 2024

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

Cadet | Tier 2
April 18, 2024

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.

Aaron.Gleason
Automation Anywhere Team
Automation Anywhere Team
April 18, 2024

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.

Cadet | Tier 2
April 26, 2024

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