2018. 9. 22.

Upload string to S3 with boto3 python

Upload string to S3 with boto3 python
# this code sometimes occurs error.  Body parameter is byte or file handle.
body_string = “abc..."
s3.client.Object(bucketname, key).put(Body= body_string) 

# using encode method. 
s3.client.Object(bucketname, key).put(Body=body_string.encode()) 


September 21, 2018 at 04:06PM

2018. 9. 5.

Write custom log in python

Write custom log in python
base_record = dict(
    name=‘module.sub’, levelname=‘error’, levelno=logging.ERROR, 
level=logging.ERROR,
funcName=‘callername’, lineno=0, args=(), exe_info=None)

record = logging.makeLogRecord(dict(base_record, msg=“some messages”))
logger.handle(record) # write log



September 05, 2018 at 11:10AM

How to get caller function name in python

get caller name
import sys

def a():
  print sys._getfrmae(1).f_code.co_name

def b():
  a()

## result
b





Tags: python, blog, flask
September 04, 2018 at 04:14PM
Open in Evernote