Repository: jschneier/django-storages

Issue:
GSResponseError: 400 Bad Request
Every time I try to `python manage.py collect static`, I get an error.

```
(venv)Dereks-MBP:pickle_django dcgoss$ python manage.py collectstatic --noinput
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.arg)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.arg)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_arg
    self.execute(*args, **cmd_options)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    collected = self.collect()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
    handler(path, prefixed_path, storage)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 321, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 234, in delete_file
    if self.storage.exists(prefixed_path):
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/storages/backends/s3boto.py", line 442, in exists
    return k.exists()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/key.py", line 539, in exists
    return bool(self.bucket.lookup(self.name, headers=headers))
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/bucket.py", line 143, in lookup
    return self.get_key(key_name, headers=headers)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/gs/bucket.py", line 108, in get_key
    query_args_l=query_args_l)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/bucket.py", line 231, in _get_key_internal
    response.status, response.reason, '')
boto.exception.GSResponseError: GSResponseError: 400 Bad Request
```

Here are my settings:

```
GS_BUCKET_NAME = os.environ['GCS_BUCKET_NAME']
GS_ACCESS_KEY_ID = os.environ['GCS_ACCESS_KEY']
GS_SECRET_ACCESS_KEY = os.environ['GCS_SECRET_KEY']

GS_CUSTOM_DOMAIN = '{bucket_name}.storage.googleapis.com'.format(bucket_name=GS_BUCKET_NAME)
MEDIA_FILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'pickle_core.settings.custom_storages.MediaStorage'
MEDIA_URL = "https://{host}/{media_files_extension}/".format(host=GS_CUSTOM_DOMAIN,
                                                             media_files_extension=MEDIA_FILES_LOCATION)
STATIC_FILES_LOCATION = 'static'
STATICFILES_STORAGE = 'pickle_core.settings.custom_storages.StaticStorage'
STATIC_URL = "https://{host}/{static_files_extension}/".format(host=GS_CUSTOM_DOMAIN,
                                                               static_files_extension=STATIC_FILES_LOCATION)
```

The custom storages references look like this:

```
class MediaStorage(GSBotoStorage):
    location = settings.MEDIA_FILES_LOCATION


class StaticStorage(GSBotoStorage):
    location = settings.STATIC_FILES_LOCATION
```

They are just there so I can access folders in my bucket.

GSResponseError: 400 Bad Request
Every time I try to `python manage.py collect static`, I get an error.

```
(venv)Dereks-MBP:pickle_django dcgoss$ python manage.py collectstatic --noinput
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.arg)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.arg)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_arg
    self.execute(*args, **cmd_options)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    collected = self.collect()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
    handler(path, prefixed_path, storage)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 321, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 234, in delete_file
    if self.storage.exists(prefixed_path):
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/storages/backends/s3boto.py", line 442, in exists
    return k.exists()
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/key.py", line 539, in exists
    return bool(self.bucket.lookup(self.name, headers=headers))
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/bucket.py", line 143, in lookup
    return self.get_key(key_name, headers=headers)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/gs/bucket.py", line 108, in get_key
    query_args_l=query_args_l)
  File "/Users/dcgoss/Desktop/PickleApp/PickleBackend/venv/lib/python3.4/site-packages/boto/s3/bucket.py", line 231, in _get_key_internal
    response.status, response.reason, '')
boto.exception.GSResponseError: GSResponseError: 400 Bad Request
```

Here are my settings:

```
GS_BUCKET_NAME = os.environ['GCS_BUCKET_NAME']
GS_ACCESS_KEY_ID = os.environ['GCS_ACCESS_KEY']
GS_SECRET_ACCESS_KEY = os.environ['GCS_SECRET_KEY']

GS_CUSTOM_DOMAIN = '{bucket_name}.storage.googleapis.com'.format(bucket_name=GS_BUCKET_NAME)
MEDIA_FILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'pickle_core.settings.custom_storages.MediaStorage'
MEDIA_URL = "https://{host}/{media_files_extension}/".format(host=GS_CUSTOM_DOMAIN,
                                                             media_files_extension=MEDIA_FILES_LOCATION)
STATIC_FILES_LOCATION = 'static'
STATICFILES_STORAGE = 'pickle_core.settings.custom_storages.StaticStorage'
STATIC_URL = "https://{host}/{static_files_extension}/".format(host=GS_CUSTOM_DOMAIN,
                                                               static_files_extension=STATIC_FILES_LOCATION)
```

The custom storages references look like this:

```
class MediaStorage(GSBotoStorage):
    location = settings.MEDIA_FILES_LOCATION


class StaticStorage(GSBotoStorage):
    location = settings.STATIC_FILES_LOCATION
```

They are just there so I can access folders in my bucket.



Discussion:

Resolving patch:
diff --git a/storages/backends/gs.py b/storages/backends/gs.py
--- a/storages/backends/gs.py
+++ b/storages/backends/gs.py
@@ -63,6 +63,7 @@ class GSBotoStorage(S3BotoStorage):
         'application/x-javascript',
     ))
     url_protocol = setting('GS_URL_PROTOCOL', 'http:')
+    host = setting('GS_HOST', GSConnection.DefaultHost)
 
     def _save_content(self, key, content, headers):
         # only pass backwards incompatible arguments if they vary from the default


Test patch: