2
votes

I've deployed a bare-bones Django app on Heroku. When I run collectstatic to upload the static files to S3, I get the following error:

Traceback (most recent call last):
  File "appname/manage.py", line 11, in 
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 135, in handle_noargs
    collected = self.collect()
  File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 33, in collect
    ret = super(Command, self).collect(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 111, in collect
    handler(path, prefixed_path, storage)
  File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 92, in copy_file
    self.destroy_lookup(prefixed_path)
  File "/app/.heroku/python/lib/python2.7/site-packages/collectfast/management/commands/collectstatic.py", line 61, in destroy_lookup
    cache.delete(self.get_cache_key(path))
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/cache/backends/memcached.py", line 86, in delete
    self._cache.delete(key)
_pylibmc.MemcachedError: error 47 from memcached_delete(:1:collectfast_asset_dc44a7965f7): SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY, host: 127.0.0.1:11211 -> libmemcached/connect.cc:592

The following env variables are set on heroku:

BUILDPACK_URL:
DATABASE_URL:
DJANGO_AWS_ACCESS_KEY_ID:
DJANGO_AWS_SECRET_ACCESS_KEY:
DJANGO_AWS_STORAGE_BUCKET_NAME:
DJANGO_CONFIGURATION:
DJANGO_SECRET_KEY:
HEROKU_POSTGRESQL_CRIMSON_URL:
MEMCACHIER_PASSWORD:
MEMCACHIER_SERVERS:
MEMCACHIER_USERNAME:
PGBACKUPS_URL:
SENDGRID_PASSWORD:
SENDGRID_USERNAME:

I have been struggling with this for a few days. Yesterday, I realized that one of the env variables was had a misspelled duplicate. After deleting the misspelled env variable, the collectstatic command worked perfectly, and the files were uploaded to S3. Now I'm working with another app and cannot get it to work.

An empty S3 bucket with the same name already exists. I have tried both user-specific and account-wide AWS credentials, but neither worked.

1

1 Answers

0
votes

I had the same problem. I've answered on the relevant GitHub issue.

For completeness here's the solution:

First add django-pylibmc-sasl==0.2.4 to requirements.txt.

Then in settings.py replace the "CACHING" section at the end of the file with:

########## CACHING

os.environ['MEMCACHE_SERVERS'] = os.environ.get('MEMCACHIER_SERVERS', '')
os.environ['MEMCACHE_USERNAME'] = os.environ.get('MEMCACHIER_USERNAME', '')
os.environ['MEMCACHE_PASSWORD'] = os.environ.get('MEMCACHIER_PASSWORD', '')

CACHES = {
  'default': {
    'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
    'LOCATION': os.environ.get('MEMCACHIER_SERVERS', ''),
    'TIMEOUT': 500,
    'BINARY': True,
    'OPTIONS': { 'tcp_nodelay': True }
  }
}

########## END CACHING

It should now work fine on Heroku.