aws cli工作正常,但Python脚本获得CERTIFICATE_VERIFY_FAILED

时间:2017-10-24 23:18:30

标签: amazon-web-services ssl aws-cli

我ssh到我的EC2实例。我可以运行这些命令,它们可以很好地工作:

aws sqs list-queues

aws s3 ls

我有一个小的Python脚本,它从数据库中提取数据,将其格式化为XML,然后将文件上传到S3。此上传失败,并显示以下错误:

Traceback (most recent call last):
  File "./data_test/data_analytics/lexisnexis/async2.py", line 289, in <module>
    insert_parallel(engine, qy, Create_Temp.profile_id, nworkers)
  File "./data_test/data_analytics/lexisnexis/async2.py", line 241, in insert_parallel
    s3upload(bucketname, keyname, f)
  File "./data_test/data_analytics/lexisnexis/async2.py", line 89, in s3upload
    bucket = conn.get_bucket(bucketname)
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 506, in get_bucket
    return self.head_bucket(bucket_name, headers=headers)
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 525, in head_bucket
    response = self.make_request('HEAD', bucket_name, headers=headers)
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 668, in make_request
    retry_handler=retry_handler
  File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 1071, in make_request
    retry_handler=retry_handler)
  File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 1030, in _mexe
    raise ex
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

即使aws cli有效,我怎么能有一个死的脚本?

要明确的是,我在运行aws cli命令时,从同一个EC2实例运行Python脚本作为同一个用户。

aws --version

aws-cli/1.11.176 Python/2.7.12 Linux/4.9.43-17.38.amzn1.x86_64 botocore/1.7.34

1 个答案:

答案 0 :(得分:1)

错误消息的最后一行告诉您问题:

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

您的问题可能是以下之一:

1)证书与您要连接的服务器有关。

2)您要连接的服务器的证书链不完整。

3)你缺少“cacert.pem”。在Google上搜索“cacert.pem”。这是一个常见问题,有很多关于下载和安装此文件的信息。

Certificate verification in Python