boto.exception.S3ResponseError:S3ResponseError:403 禁止

2024-03-05

我试图让 django 将静态文件上传到 S3,但我收到了 403 禁止错误,我不知道为什么。

完整的堆栈跟踪:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 89, in handle_noargs
    self.copy_file(path, prefixed_path, storage, **options)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 184, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage, **options):
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in delete_file
    if self.storage.exists(prefixed_path):
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/storages/backends/s3boto.py", line 209, in exists
    return k.exists()
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/boto/s3/key.py", line 391, in exists
    return bool(self.bucket.lookup(self.name))
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/boto/s3/bucket.py", line 143, in lookup
    return self.get_key(key_name, headers=headers)
  File "/home/levi/Projects/DoneBox/.virtualenv/local/lib/python2.7/site-packages/boto/s3/bucket.py", line 208, in get_key
    response.status, response.reason, '')
boto.exception.S3ResponseError: S3ResponseError: 403 Forbidden

设置.py的内容:

import os
DIRNAME = os.path.dirname(__file__)
# Django settings for DoneBox project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', '[email protected] /cdn-cgi/l/email-protection'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': os.path.join(DIRNAME, "box.sqlite"),                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Denver'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = "d1eyn4cjl5vzx0.cloudfront.net"

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(DIRNAME, "static")

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = "d280kzug7l5rug.cloudfront.net"

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(DIRNAME, "main", "static"),
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '<snip>'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'DoneBox.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(DIRNAME, "main", "templates"),
    os.path.join(DIRNAME, "templates"),
    os.path.join(DIRNAME, "basic", "blog", "templates"),
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sitemaps',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'storages',
    'django.contrib.admindocs',
    'main',
    'contacts',
    'piston',
    'registration',
#    'contact_form',
    'basic',
    'basic.blog',
)

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django.db.backends': {
            'handlers': ['mail_admins'],
            'level': 'DEBUG',
            'propagate': True,
        }
    }
}

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_ACCESS_KEY_ID = '<snip>'
AWS_SECRET_ACCESS_KEY = '<snip>'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_STORAGE_BUCKET_NAME = "donebox-static"
STATIC_FILES_BUCKET = "donebox-static"
MEDIA_FILES_BUCKET = "donebox-media"
ACCOUNT_ACTIVATION_DAYS = 7

EMAIL_HOST = "email-smtp.us-east-1.amazonaws.com"
EMAIL_HOST_USER = '<snip>'
EMAIL_HOST_PASSWORD = '<snip>'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
     "django.core.context_processors.debug",
     "django.core.context_processors.i18n",
     "django.core.context_processors.media",
     "django.core.context_processors.static",
     "django.contrib.messages.context_processors.messages",
     "DoneBox.main.context_processors_PandC",
     )

需求.pip的内容:

django==1.3
django-storages==1.1.4
django-registration==0.8
django-piston==0.2.3
django-tagging==0.3.1
django-extensions==0.8
BeautifulSoup==3.2.1
boto==2.4.1
mysql-python==1.2.3
tweepy==1.9
feedparser==5.1.2
pycrypto==2.6

谷歌搜索此异常并没有发现任何有趣的东西。我怀疑我配置错误,尽管我不确定。有人能指出我正确的方向吗?感谢您的时间和考虑。


我正在使用 Amazon IAM 作为特定密钥 ID 和访问密钥,但刚刚遇到了相同的 403 Forbidden...事实证明,您需要授予目标权限both存储桶根及其子对象:

{
  "Statement": [
    {
      "Principal": {
          "AWS": "*"
      },
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": ["arn:aws:s3:::bucket-name/*", "arn:aws:s3:::bucket-name"]
    }
  ]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

boto.exception.S3ResponseError:S3ResponseError:403 禁止 的相关文章

随机推荐

  • 比较数组与 jQuery [重复]

    这个问题在这里已经有答案了 可能的重复 javascript中数组交集的最简单代码 https stackoverflow com questions 1885557 simplest code for array intersection
  • 检查 TCP 端口是否可用(未侦听或连接)

    我使用以下代码来检查端口是否可用 bool ClassA CheckPortTCP short int dwPort char ipAddressStr struct sockaddr in client int sock client s
  • 在 C# 中调用 google Url Shortener API

    我想打电话给谷歌网址缩短API http code google com apis urlshortener v1 getting started html从我的 C 控制台应用程序中 我尝试实现的请求是 POST https www go
  • Firestore - 查询时如何在字段上应用“字符串包含”条件?

    Collection Post postId post 124 title World population 2020 如何编写一个查询 返回 标题 字段中包含字符串 世界人口 的帖子 Firestore 不支持此级别的查询 看全文检索 h
  • 从 iOS 应用程序检测附近的移动设备

    是否可以创建一个 iOS 应用程序来扫描附近的移动设备 例如 iPhone Android iPad 等 而无需在附近的移动设备上运行任何自定义应用程序 我尝试过像这样使用 CoreBluetooth 在我的 iPhone 6 上运行 se
  • 如何创建数据类型不是 EMF 类的 EAttribute?

    使用 EMF 我想定义一个属性 其数据类型 EType 在我的 EMF 模型外部 也就是说 我想要的类型是一个普通的手工编码的 Java 类 它不是我的 EMF 模型的一部分 使用AnySimpleType是最后的手段 与使用泛型相比 我想
  • 从一个线程跟踪另一个线程

    进行实验ptrace 系统调用 我试图跟踪同一进程的另一个线程 根据手册页 跟踪器和被跟踪者都是特定的线程 而不是进程 所以我看不出它不应该工作的原因 到目前为止 我已经尝试了以下方法 use PTRACE TRACEME来自clone d
  • 读取会话变量而不使上下文无效

    有没有办法在会话变量发生变化时读取会话变量而无需重新渲染模板 场景 我使用 jQuery 动态更改元素的样式 但是当创建新元素时 我想设置其默认样式 我知道在渲染元素时我可以调用相同的 jQuery 命令 Example
  • C# Visual Studio 如何重新定位 nuget 包文件夹?

    我聘请了一名承包商为我做一些编码 他使用以下存储库路径在解决方案文件夹中设置 nuget config
  • 在 Heroku 中使用特殊字符设置环境变量(通过 powershell)

    Django 1 8 Heroku Powershell 我正在尝试在 Heroku 中为 django 密钥设置环境变量 venv PS WORKFOLDER gt heroku config set SECRET KEY eoik6 d
  • 改变UIView位置的简单方法?

    我使用以下代码更改 UIView 的位置 而不更改视图的大小 CGRect f aView frame f origin x 100 new x f origin y 200 new y aView frame f 有没有更简单的方法来仅更
  • 文本二值化

    I d like to binarize this image to use it with tesseract ocr Currently I managed to get this But I need clear image with
  • SQL Server 2008 Nvarchar(Max) 连接 - 截断问题

    有人可以解释一下为什么在 SQL Server 2008 上会发生这种情况吗 declare sql Nvarchar max set sql N select sql sql replicate a 4000 replicate b 60
  • 使用 Python 请求传递登录名/密码

    我查看了相关答案 但没有找到非常有效的东西 我正在尝试从我的球队的 CBS Sportsline 页面上抓取一些梦幻棒球信息 我想发布登录名和密码 然后当我使用 get 命令时 查看特定于我的帐户的数据 这是我尝试过的 import req
  • 发送对象时忽略 JSON 字段(反序列化)

    我有一个 DTO 对象 public class Rate private final Integer rate private final String user private final Date date 和两个控制器 https
  • 正确处理浏览器资源

    我有一个网络应用程序 可以在很长一段时间内动态加载数据 数据内有图像的链接 然后在浏览器中呈现这些图像 e g var object Name ko observable Foo Ref ko observable Bar ImageUrl
  • ASP.NET MVC Web 应用程序中视图逻辑和域逻辑之间的混淆

    我对域 应用程序逻辑和用户界面逻辑感到困惑 为了说明我想要确定的内容 我将在下面描述一个虚构的程序以供说明 1 想象一个带有一组 3 个级联下拉菜单的小型应用程序 当您选择一个下拉列表时 它会触发 jQuery Ajax GET 最终到达
  • 防止并行操作按顺序批量执行

    我有 8 个逻辑处理器 当执行以下代码时 public void test Parallel For 1 1001 i gt IntensiveWork i private static void IntensiveWork int i R
  • 如何列出所有提交到存储库的文件?

    我如何让 SVN 列出曾经提交到存储库的所有文件 如果可能 以及位置和修订版本 更准确地说 我需要所有曾经存在的路径 如果有人知道如何对整个存储库 包括all修订 这会对我有更好的帮助 Example 假设我提交了一个文件SomeFileO
  • boto.exception.S3ResponseError:S3ResponseError:403 禁止

    我试图让 django 将静态文件上传到 S3 但我收到了 403 禁止错误 我不知道为什么 完整的堆栈跟踪 Traceback most recent call last File manage py line 14 in