Hi I have a query in this form :
data = {
"pg_content": "CREATE OR REPLACE TABLE CREDITCARDS.CC_TRANSACTION(\n TRANSACTION_ID DECIMAL COMMENT 'Identifier.Values between 0 and 23162883'\n ACCOUNT_NUMBER VARCHAR COMMENT 'Categorical Attribute with specific values as ACC2060,ACC1188,ACC1437,ACC5552,ACC98,ACC2240,ACC4096,ACC5555,ACC22,ACC4232'\n TRANSACTION_AMOUNT DECIMAL COMMENT 'Values between -6125.96 and 600.00'\n TRANSACTION_DATE DATE COMMENT 'Values between 2023-01-09 and 2023-06-16'\n TRANSACTION_TYPE VARCHAR COMMENT 'Categorical Attribute with specific values as Purchase,Cash Advance,Void,Refund,Verification,Payment'\n MERCHANT_NAME VARCHAR COMMENT 'Categorical Attribute with specific values as Merchant 250575,Merchant 265897,Merchant 54632,Merchant 100866,Merchant 749929,Merchant 250268,Merchant 486642,Merchant 27292,Merchant 250396,Merchant 108175',\n PRIMARY KEY(TRANSACTION_ID),\n FOREIGN KEY(ACCOUNT_NUMBER) REFERENCES CREDITCARDS.CREDIT_CARD_ACCOUNT(ACCOUNT_NUMBER)\n); "
}
I want to write this content to a txt file and upload it to s3 but during upload I am getting this error :
[ERROR] AttributeError: 'int' object has no attribute 'encode
My code is :
local_file_name = 'local_file'
metadata = {'_id':123 , 'name':'new'}
text_file_path = '/tmp/' + str(local_file_name) + '.csv'
s3_client = boto3.client('s3')
with open(text_file_path, 'w') as file:
file.write(data.get('pg_content'))
# Upload the text file to S3
s3_client.upload_file(text_file_path, bucket_name, file_name)
s3_client.put_object(
Bucket=bucket_name,
Key=file_name,
Metadata=metadata
)
So This turn out to be that Metadata should not be integer so by doing this:
metadata = {'_id': '123' , 'name':'new'}
solved my problem