I'm having issues while running collectstatic in macOS. The error is OSError: [Errno 45] Operation not supported: '/home/juan'
./manage.py collectstatic
Copying '/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/admin/static/admin/css/widgets.css'
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 189, in handle
collected = self.collect()
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
self.storage.save(prefixed_path, source_file)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/lib/python3.6/site-packages/django/core/files/storage.py", line 236, in _save
os.makedirs(directory)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/Users/juan/Documents/manu/dev/sw/webwatcher/venv/bin/../lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
OSError: [Errno 45] Operation not supported: '/home/juan'
----------
The same command in the same project is running fine in ubuntu
Concerning the people who have this problem. You need to set your static, media root directories and URLs properly. Here is an example:
settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
urls.py:
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
Related
I got this error when trying to host my django project on heroku FileNotFoundError: [Errno 2] No such file or directory: '/app/static'
here is settings.py:
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
and this is the error :
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 105, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 316, in listdir
for entry in os.scandir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/static'
The differences between STATICFILES_DIRS, STATIC_ROOT, MEDIA_ROOT, etc. can be confusing. In your case, you can start by removing the first line of your settings.py, because STATIC_DIR is not a Django settings variable.
Then, the actual cause of your problem is that directory specified in the Django's settings variable STATICFILES_DIRS does not exist:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
On the Heroku server, this path is /app/static, but on you own computer it likely lives in a location such as $HOME/awesome-django-project/static. Creating the directory there will hopefully solve the problem.
Alternatively, you could remove the setting STATICFILES_DIRS altogether and place your staticfiles inside app directories. I personally prefer this approach because it makes the settings simpler and your source code directory cleaner.
I'm a bit new to django and I'm trying to run collectstatic from the terminal (python manage.py collectstatic) in order to collect the static files in the S3 bucket but I getting the following error:
$ python manage.py collectstatic
C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\storages\backends\s3boto3.py:282: UserWarning: The default behavior of S3Boto3Storage is insecure and will change in django-storages 2.0. By default files and new buckets are saved with an ACL of 'public-read' (globally publicly readable). Version 2.0 will default to using the bucket's ACL. To opt into the new behavior set AWS_DEFAULT_ACL = None, otherwise to silence this warning explicitly set AWS_DEFAULT_ACL.
"The default behavior of S3Boto3Storage is insecure and will change "
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 199, in handle
collected = self.collect()
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 354, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\storages\backends\s3boto3.py", line 532, in exists
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\storages\backends\s3boto3.py", line 315, in connection
verify=self.verify,
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\boto3\session.py", line 389, in resource
aws_session_token=aws_session_token, config=config)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\boto3\session.py", line 263, in client
aws_session_token=aws_session_token, config=config)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\session.py", line 839, in create_client
client_config=config, api_version=api_version)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\client.py", line 86, in create_client
verify, credentials, scoped_config, client_config, endpoint_bridge)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\client.py", line 328, in _get_client_args
verify, credentials, scoped_config, client_config, endpoint_bridge)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\args.py", line 47, in get_client_args
endpoint_url, is_secure, scoped_config)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\args.py", line 117, in compute_client_args
service_name, region_name, endpoint_url, is_secure)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\client.py", line 402, in resolve
service_name, region_name)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\regions.py", line 122, in construct_endpoint
partition, service_name, region_name)
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\regions.py", line 141, in _endpoint_for_partition
if self._region_match(partition, region_name):
File "C:\Users\Elena\Desktop\Curso\4th Module\ecommerce2\.venv\lib\site-packages\botocore\regions.py", line 159, in _region_match
return re.compile(partition['regionRegex']).match(region_name)
TypeError: expected string or bytes-like object
(.venv)
Steps that I have followed:
I have installed django-storages and boto3
pip install django-storages
pip install boto3
I have added 'storages' to INSTALLED_APPS in settings.py
I have created 'custom_storage.py'
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
I have added the following to settings.py
AWS_S3_OBJECT_PARAMETERS = {
'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
'CacheControl': 'max-age=94608000'
}
AWS_STORAGE_BUCKET_NAME = 'elena-ecommerce'
AWS_S3_REGION_NAME = 'eu-west-2',
AWS_ACCESS_KEY_ID = os.environ.get("AWS_SECRET_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storage.StaticStorage'
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR,"static"),)
And the I have run the following command:
python manage.py collectstatic
The problem is in the settings file where you have mentioned as AWS_S3_REGION_NAME = 'eu-west-2', there is a comma after eu-west-2, remove that and it will work. The comma after the string create a tuple like this, ('eu-west-2',) instead of string, whereas the re match expects a string
I just mentioned a sample
>>> AWS_S3_REGION_NAME = 'eu-west-2',
>>> print(AWS_S3_REGION_NAME)
('eu-west-2',)
>>> AWS_S3_REGION_NAME = 'eu-west-2'
>>> print(AWS_S3_REGION_NAME)
eu-west-2
Refer: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
I'm trying to run a gitlab project on a local machine. I have a problem at the start of the command
manage.py collectstatic
error
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 354, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/y700/Env/healthline/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 260, in delete_file
if self.storage.exists(prefixed_path):
File "/home/y700/Env/healthline/lib/python3.7/site-packages/storages/backends/s3boto3.py", line 532, in exists
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 634, in _make_api_call
api_params, operation_model, context=request_context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 680, in _convert_to_request_dict
api_params, operation_model, context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/client.py", line 712, in _emit_api_params
params=api_params, model=operation_model, context=context)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/home/y700/Env/healthline/lib/python3.7/site-packages/botocore/handlers.py", line 219, in validate_bucket_name
if VALID_BUCKET.search(bucket) is None:
TypeError: expected string or bytes-like object
I tried to update the boto3 version, but it didn't help.
settings.py (part)
....
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app', 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
....
else I have settings for AWS server
AWS_LOCATION = 'static'
DEFAULT_FILE_STORAGE = 'app.storage_backends.PrivateMediaStorage'
AWS_PUBLIC_STATIC_LOCATION = 'static/'
I've found similar questions but they were from years ago and the solutions haven't worked so far.
Here's the traceback:
(devtm) λ heroku run python manage.py collectstatic
Running python manage.py collectstatic on ⬢ {appname}... up, run.1335 (Free)
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, 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 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/files/storage.py", line 397, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/app/{appname+"site"}/assets'
Here's my settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../{appname+"site"}/assets'),
os.path.join(BASE_DIR, '../{appname+"site"}/assets/css'),
os.path.join(BASE_DIR, '../{appname+"site"}/assets/images'),
os.path.join(BASE_DIR, '../{appname+"site"}/assets/js'),
os.path.join(BASE_DIR, '../{appname+"site"}/assets/venue_images')
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
I've tried adding a directory (with blank file for git) named staticfiles to my root (so next to the manage.py file). I've tried adding a folder/file named assets in the folder with the settings.py file, which appears to be where the traceback is indicating the error. I've also tried pathing without the .. portion and without the ../{appname}+"site" portion.
This is my first attempt at launching a Django site on Heroku and I've been struggling for more than a week on this. I've read tons of documentation and SO posts, but haven't been able to pinpoint the problem.
Your strings are not being manipulated based on output. They are quoted.
Try changing where applicable, example:
Note:
I have no idea what appname is, if it's a variable or literal.
Try changing the below statement and others similar to
os.path.join(BASE_DIR, '../{appname+"site"}/assets/css')
To:
os.path.join(BASE_DIR, '../{appname'+'site' +'}/assets/css');
Hi I have Django web page and I am migrating to GCloud. I have successfully migrated the DB and now I am trying to migrate the Static and Media storages.
I have this in my settings:
INSTALLED_APPS.append('storages')
GS_ACCESS_KEY_ID = env('GS_ACCESS_KEY_ID')
GS_SECRET_ACCESS_KEY = env('GS_SECRET_ACCESS_KEY')
GS_BUCKET_NAME = env('GS_BUCKET_NAME')
from storages.backends.gs import GSBotoStorage
StaticGStorage = lambda: GSBotoStorage(location='static')
MediaGStorage = lambda: GSBotoStorage(location='media')
MEDIA_URL = 'https://storage.googleapis.com/{}/media/'.format(GS_BUCKET_NAME)
STATIC_URL = 'https://storage.googleapis.com/{}/static/'.format(GS_BUCKET_NAME)
DEFAULT_FILE_STORAGE = 'config.settings.local.MediaGStorage'
STATICFILES_STORAGE = 'config.settings.local.StaticGStorage'
I followed this: Configure Django and Google Cloud Storage?
In Access key env variables are values from "Interoperability" tab in Settings in GCloud Storage and I am 100% sure that they are loaded correctly. Also the bucket name is correct.
But I am still getting this exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 349, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/usr/local/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 255, in delete_file
if self.storage.exists(prefixed_path):
File "/usr/local/lib/python3.5/site-packages/storages/backends/s3boto.py", line 454, in exists
return k.exists()
File "/usr/local/lib/python3.5/site-packages/boto/s3/key.py", line 539, in exists
return bool(self.bucket.lookup(self.name, headers=headers))
File "/usr/local/lib/python3.5/site-packages/boto/s3/bucket.py", line 143, in lookup
return self.get_key(key_name, headers=headers)
File "/usr/local/lib/python3.5/site-packages/boto/gs/bucket.py", line 111, in get_key
query_args_l=query_args_l)
File "/usr/local/lib/python3.5/site-packages/boto/s3/bucket.py", line 231, in _get_key_internal
response.status, response.reason, '')
boto.exception.GSResponseError: GSResponseError: 403 Access denied to 'gs://my-bucket-name/static/css/material.grey-orange.min.css'.
I get this exception from command:
python manage.py collectstatic --noinput
I should probably set something in the GCloud console but I have no idea what is wrong.
Thanks for help