在Heroku上使用Boto时,无法连接到名称中包含句点的S3存储桶

Yar*_*rin 17 python heroku amazon-s3 boto amazon-web-services

尝试使用Boto连接到我们的S3存储桶时,我们收到了证书错误.奇怪的是,这只会在访问一个名为WHILE的句点时使用Heroku运行时显示出来.

from boto.s3.connection import S3Connection
conn = S3Connection({our_s3_key}, {our_s3_secret})
bucket = conn.get_bucket('ourcompany.images')
Run Code Online (Sandbox Code Playgroud)

引发以下错误:

CertificateError:主机名'ourcompany.images.s3.amazonaws.com'与'*.s3.amazonaws.com','s3.amazonaws.com'不匹配

但是相同的代码在本地运行时工作正常,如果存储桶名称是'ourcompany-images'而不是'ourcompany.images',它也适用于Heroku

ale*_*cxe 37

根据相关的github问题,将其添加到配置中:

[s3]
calling_format = boto.s3.connection.OrdinaryCallingFormat
Run Code Online (Sandbox Code Playgroud)

或者,指定calling_formatwhile实例化S3Connection:

from boto.s3.connection import OrdinaryCallingFormat

conn = S3Connection(access_key, secret_key, calling_format=OrdinaryCallingFormat())
Run Code Online (Sandbox Code Playgroud)

由于使用了不同的python版本,代码很可能在本地为你工作,并且在heroku上不起作用.我怀疑你2.7.9在heroku 上使用运行时,它已经为stdlib http客户端启用了证书检查.

  • 对于所有使用流行的Django-Storages包装器的人来说,这可以通过你的应用程序的settings.py来完成,如下所述:https://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html and here: https://bitbucket.org/david/django-storages/issue/181/from-s3-import-callingformat-seems-broke (6认同)