Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boto [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed while connecting to S3

I am trying to connect to S3 using boto, but it seems to fail. I've tried some workarounds, but they don't seem to work. Can anyone please help me with this. Below is the code.

import boto

if not boto.config.has_section('Credentials'):
    boto.config.add_section('Credentials')
boto.config.set('Credentials', 'aws_access_key_id', AWS_KEY)
boto.config.set('Credentials', 'aws_secret_access_key', AWS_SECRET_KEY)
if not boto.config.has_section('Boto'):
    boto.config.add_section('Boto')
    boto.config.set('Boto', 'https_validate_certificates', 'False')
    boto.config.add_section('aws info')
    boto.config.set('aws info','aws_validate_certs','False')



s3 = boto.connect_s3(validate_certs=False)
bucket = s3.get_bucket(Bucket_NAME)
like image 831
Siddarth Avatar asked Jan 23 '15 17:01

Siddarth


4 Answers

Probably your bucket name contains a dot, that's why ssl certificate verification fails. This is quite a frequent problem, see this github issue for example.

Don't use an insecure connection (is_secure=False), instead use OrdinaryCallingFormat:

import boto
conn = boto.s3.connect_to_region('eu-west-1', calling_format=boto.s3.connection.OrdinaryCallingFormat())
bucket = conn.get_bucket(your_bucket)

You probably need to update your AWS Region, e.g. us-east-1

like image 166
linqu Avatar answered Nov 18 '22 17:11

linqu


In boto3, if you are using the s3 client, use verify=False when creating the s3 client. For eg:

s3 = boto3.client('s3', verify=False)

As mentioned on boto3 documentation, this only turns off validation of SSL certificates. SSL will still be used (unless use_ssl is False), but SSL certificates will not be verified.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html

like image 35
peaxol Avatar answered Nov 18 '22 19:11

peaxol


I found a way,

used is_secure=False in connect_s3().

like image 10
Siddarth Avatar answered Nov 18 '22 18:11

Siddarth


I encounter this problem, too. My environment is Ubuntu 15.04, Python 2.7.9 and Boto 2.38.0.

Setting the argument validate_certs=False doesn't make it work with the HTTPS connection without valid certificate. After reading the code of boto, I found that it's a behavior of Python's ssl modules. Then I found a solution here: "SSL: CERTIFICATE_VERIFY_FAILED" Error. And the solution does work!!!.

like image 3
diabloneo Avatar answered Nov 18 '22 18:11

diabloneo