Python : Pipe is broken

Hi,
I’m working on invoking the python script in my project to decrypt the encrypt and decrypt the password using the AWS KMS service. I have created the python code and tested it locally which works fine while running through the python IDE.

when I tried to “Invoke python method” I’m getting a pipe is a broken error on the UI path.
Could someone please provide some feedback/suggestions on this?

Appreciate your help. Let me know if you need more details.

Python Code

import base64
import boto3


def encrypt(secret):
    session = boto3.session.Session()

    key_id = 'alias/xxxx'
    client = session.client('kms',
                            region_name='us-east-1',
                            aws_access_key_id="xxxxx",
                            aws_secret_access_key="xxxxx"
                            )
    ciphertext = client.encrypt(
        KeyId=key_id,
        Plaintext=bytes(secret, 'utf-8'),
    )
    return base64.b64encode(ciphertext["CiphertextBlob"])

@Hari_Balaji,

Try placing the import Statements inside the function and Check.

Could you also specify the Working Folder i.e the Current Directory Folder and Check.

Hello @supermanPunch ,

Thanks, I have replaced the import inside the def function itself and added a working directory still getting the same error. When I tried to run the code on windows cmd it worked.

Is there any other possibility…?

def encrypt(secret):
    import base64
    import boto3
    session = boto3.session.Session()
    key_id = 'alias/xxxx'
    client = session.client('kms',
                            region_name='us-east-1',
                            aws_access_key_id="xxxxx",
                            aws_secret_access_key="xxxxx"
                            )
    ciphertext = client.encrypt(
        KeyId=key_id,
        Plaintext=bytes(secret, 'utf-8'),
    )
    return base64.b64encode(ciphertext["CiphertextBlob"])

Hello,
I have figured out the issues and fixed them.
The actual issue was I have two python versions installed on the windows machine which cause the trouble. When is initialize the bot it takes the default python and pip environment while invoking the python process.

What I did was add the python path on the system environment variable to the local machine so that it will alias to the required version and also added the pip environment folder into the system environment variable.

To get the python path open cmd and run below cmd.

where python

To check the pip run the below cmd

pip --help

Once we add it double-check the python path on the UI path and the function used to invoke it.

That solved my issues. I hope this might help others. Thanks!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.