I want to encrypt a message using python in A360
code
from cryptography.fernet import Fernet
def enfun():
message=‘Hello Automation’
key=Fernet.generate_key()
f=Fernet(key)
encryptedmessage=fernet.encrypt(message.encode())
return encryptedmessage
Installed pip3 install cryptography library. When I run above code the python script is returning bot error to the output variable.
I’m able to run same code in cmd but not from A360
Thanks in Advance
Hi @Sparimi ,
Can you please share the screenshot of how you wrote the above script in Python execute function action
Hi @Sparimi ,
Are you passing any parameter to python from BOT? If yes, you need to change the code especially at the function declaration.
It’s working now syntax mistake
thanks for the response @Zaid Chougle @Padmakumar
I am having the same issue in A360
import mysql.connector
from mysql.connector import Error
def execute_query(query, host, user, password, database):
try:
# Establish the connection
connection = mysql.connector.connect(
host=host,
user=user,
password=password,
database=database
)
if connection.is_connected():
# Create a cursor object using the connection
cursor = connection.cursor()
# Execute the SQL query
cursor.execute(query)
# Fetch all results from the executed query
results = cursor.fetchall()
# Return the results
return results
except Error as e:
print(f"Error: {e}")
return None
finally:
# Ensure the cursor and connection are closed properly
if 'cursor' in locals() and cursor is not None:
cursor.close()
if 'connection' in locals() and connection.is_connected():
connection.close()
# Example usage:
if __name__ == "__main__":
query = 'SELECT * FROM automation.medicaid where process="INVOICE"'
host = 'localhost'
user = 'root'
password = 'root'
database = 'automation'
results = execute_query(query, host, user, password, database)
if results is not None:
for row in results:
print(row)
Cmd Output: ('INVOICE', 'Y')
Bot Output: Bot Error
Hi,
You need to make sure the below steps;
- Check if your python path is added in environment variable (to verify, you just need to open CMD and write “python”. if python is added then it will execute the line or will through error that python is not recognised).
- Check for code indentation. (Try not to copy the script from notepad to AA Python Open activity it will make an indentation issue which will cause bot error issue).
- Make sure your python function won’t have more then one input parameter.
Sanobar Khan