Category : python-3.x

I download a file from S3 like this: s3 = boto3.client(‘s3’) s3.download_file(‘testunzipping’,’DataPump_10000838.zip’,’/tmp/DataPump_10000838.zip’) For now it always works. However, I wanted to add some sort of error handling. How can I check or get an error message if the download fails. How would I know that there’s something wrong? Does boto3 offer any error handling functions? ..

Read more

I’m browsing a dictionary to delete some values in another dictionary. However, pylint doesn’t like my code and suggest me to use .items() method. I discover this method and I don’t understand how to get the same result with this. My dictionaries look like that : itemsToDelete = { 1: { "page1": "item1", "page1": "item2", ..

Read more

I want to save a record using psycopg2 in Python3, this is my code looks like: # coding:utf8 import time from sqlalchemy import Column, String, Integer from dolphin.common.commonlogger import CommonLogger from dolphin.common.db.DatabaseService import Base, dict_session_scope logger = CommonLogger().get_logger() class Sentence(Base): __tablename__ = ‘sentence’ id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) word_id = Column(Integer, primary_key=False, nullable=False) created_time ..

Read more

Previously, I was uploading files to Amazon S3 like this and it worked fine: bucket.upload_fileobj( io.BytesIO(gzipped_content), fileName2, ExtraArgs={"ContentType": "text/plain"}) In this case, fileName2 was placed directly into the bucket’s root folder. Now I want to place fileName2 in sub folders. Like this: bucket/year/month/day/fileName2. I have variables year/month/day saved as strings with me. I tried this: ..

Read more

I am trying to Automate the dataset creation in quicksight using Boto3. but I am stuck some point . please any one help to solve this. Here my code : qs = boto3.client(‘quicksight’) response = qs.describe_data_set( AwsAccountId=’xxxxxxxx’, DataSetId=’testdatasetv4′ ) columns =response[‘DataSet’][‘PhysicalTableMap’][‘string’][‘RelationalTable’][‘InputColumns’] for dic in columns: for key in dic: print({dic[key]}) I need a output like ..

Read more