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

Question:

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)
Asked By: Siddarth

||

Answers:

I found a way,

used is_secure=False in connect_s3().

Answered By: Siddarth

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

Answered By: linqu

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!!!.

Answered By: diabloneo

macOS users: If you are using the Python 3.6 from the python.org
binary installer linked on this page, please carefully read the
Important Information displayed during installation; this information
is also available after installation by clicking on
/Applications/Python 3.6/ReadMe.rtf. There is important information
there about changes in the 3.6.0 installer-supplied Python,
particularly with regard to SSL certificate validation.

https://www.python.org/downloads/release/python-360/

From ReadMe.rtf at the time of this writing:

Certificate verification and OpenSSL

NEW This variant of Python 3.6 now includes its own private copy of OpenSSL 1.0.2. Unlike previous releases, the deprecated
Apple-supplied OpenSSL libraries are no longer used. This also means
that the trust certificates in system and user keychains managed by
the Keychain Access application and the security command line utility
are no longer used as defaults by the Python ssl module. For 3.6.0, a
sample command script is included in /Applications/Python 3.6 to
install a curated bundle of default root certificates from the
third-party certifi package (https://pypi.python.org/pypi/certifi).
If you choose to use certifi, you should consider subscribing to the
project’s email update service to be notified when the certificate
bundle is updated.

The bundled pip included with the Python 3.6 installer has its own
default certificate store for verifying download connections.

Answered By: steamer25

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

Answered By: peaxol

add verify=False

boto3.resource(
            "s3",
            endpoint_url=<URL>,
            aws_access_key_id=<ID>,
            aws_secret_access_key=<Key>,
            verify=False
        )
Answered By: saptarshi

Office laptops usually have network monitors installed. Figured out that it was the network monitoring software interfering with python, not letting it verify ssl certs of aws. We had to import its’s cert(got from office) onto python’s cacert.pem file, then it started working fine.

Answered By: Vasudev