Skip to main content

using community version and open a python script manual input

 

import json

  

def myfunc(mystr: str) -> str:

  data = json.loads(mystr)

  return datan'meta']

 

when I call the function myfunc passing a string I get bot error. The string is json returned from an rest api call, when I put the script in a py file and run from desktop command line it works fine.

 

I worked 1 time then it keeps returning bot error. I noticed lots of issues on forum with this type of issue: running python in AAI

Hi @mark fung-a-fat​ ,

 

Can you share your AA Code Snippet?


Chandu

 

import json

  

def myfunc(mystr: str) -> str:

  data = json.loads(mystr)

  return datan'meta']

 

this is the code I put in the open script: manual

 

this is the code that I put into the function call and i pass a string that is json that returned from my rest call

 

image 

image


Hi @mark fung-a-fat​ ,

 

Could you try the following snippet and see if that works out for you?

 

import json

 

def myfunc(mystr):

 data = json.loads(mystr)

 return datau'meta']

 

Kind Regards,

Ashwin A.K


ashwin



this worked thank you.

Glad I could help!

 

I'd appreciate it if you marked my solution as "Best" so that others facing similar issues may benefit from it as well.

 

Kind Regards,

Ashwin A.K


Hi @Ashwin A.K and @ChanduMohammad , I am executing this script outside A360 and getting response but while executing same in A360 it is saying Bot error. Can you please check and let me know where exactly the issue is? do I need to install any libraries, if yes please guide me through. thank you.

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):
    #AK/SK information
    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__':
    # miral test env 
    strAKID = "e2c5b464-5361-40f2-9c8e-bc04962db1a7"
    strAKSecret = "I5lGga3vfFW8Nf9HbRHuUnROcga0SnpP"
    authorization(strAKID, strAKSecret)


Reply