Search code examples
python-3.xamazon-s3aws-lambdaboto3dbf

Reading dbf file from s3 throwing error - 'int' object has no attribute 'isalpha'


I am developing a python aws lambda function for migrating dbf files into mysql after reading it from s3. Lambda function get triggered after every dbf file upload. Here is my code,

 import boto3
 import io 
 from dbfread import DBF 
 s3 = boto3.client('s3')
 obj = s3.get_object(Bucket='XXXXXX', Key='test.dbf')
 f   = io.BytesIO(obj['Body'].read())
 for line in f.readlines():    
     for r in DBF(line,encoding='utf-8'):
         print(r)

enter image description here

but when I am executing the script I'm getting the below error.

File "E:\Projects\dbf_mysql_migration\dbfread\dbf.py", line 108, in __init__
    self.filename = ifind(filename)
  File "E:\Projects\dbf_mysql_migration\dbfread\ifiles.py", line 55, in ifind
    files = iglob(pat)
  File "E:\Projects\dbf_mysql_migration\dbfread\ifiles.py", line 44, in iglob
    return glob.glob(ipat(pat))
  File "E:\Projects\dbf_mysql_migration\dbfread\ifiles.py", line 24, in ipat
    if c.isalpha:
AttributeError: 'int' object has no attribute 'isalpha'

Can you please help me? Is there any better way to read dbf files as streams from s3 .


Solution

  • I had the same issue, and I solved following the next steps:

    1. Create linux ec2 instance
    2. Mount S3 bucket as a filesystem in the linux ec2 instance
    3. Write a Python function reading the files with the sentence dbf_data = DBF(file, encoding='iso-8859-1')