Boto3 in Lambda function - RequestsDependencyWarning

Viewed 279

I'm trying to upload a file to s3 from lambda function.

from openpyxl import load_workbook
from openpyxl.styles import PatternFill, Color
import requests
from io import BytesIO
import os
import boto3
from tempfile import NamedTemporaryFile
import json

response = requests.get(file_url, stream=True)
print("File downloaded...")
wb = load_workbook(filename=BytesIO(response.raw.read()), keep_vba=True)
print("Workbook loaded from memory...")
sheet = wb['Data']
color = Color(rgb='00FF0000')
err_fill = PatternFill(fill_type='solid', fgColor=color)
for err in errors:
    sheet[err['cell']].fill = err_fill

# Remove correct rows
for rec in recipients:
    recipient = rec['recipient']
    if 'errors' not in recipient.keys() or len(recipient['errors']) < 1:
        row = recipient['row']
        sheet.delete_rows(row)
session = boto3.Session()
s3 = session.client('s3')
try:
    with NamedTemporaryFile() as tmp:
        wb.save(tmp.name)
        filename = '{0}_err1.xlsm'.format(request_id)
        response = s3.upload_file(tmp.name, 'bucket_name', 'excel/'+filename)
        print("S# Response: ", response)
        return 'url{0}'.format(filename)
except Exception:
    print("Some error occurred.. ", Exception)
    return None

I'm getting following error in cloudwatch logs.

/var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (4.0.0) doesn't match a supported version!

When I run the same locally It works fine. I'm deploying the lambda function using AWS toolkit for pycharm. Here's my pip freeze output.

boto3==1.16.56
botocore==1.19.56
certifi==2020.12.5
chardet==4.0.0
et-xmlfile==1.0.1
idna==2.10
jdcal==1.4.1
jmespath==0.10.0
numpy==1.19.5
openpyxl==3.0.6
pandas==1.1.5
pymongo==3.11.2
python-dateutil==2.8.1
pytz==2020.5
requests==2.25.1
s3transfer==0.3.4
six==1.15.0
urllib3==1.26.2

Any pointers to resolve this?

0 Answers
Related