我正在努力在AWS上部署Django应用。在本地,一切正常。部署后,该网站可以很好地打开,但是当我尝试运行深度学习模型时,它给了我Errno 13权限错误。 / severity是发生这种情况的网站页面。任何和所有帮助表示赞赏:)
网站上显示的错误
Request Method: POST
Request URL: http://radiology-ai-env.eba-wgmpba4k.us-west-2.elasticbeanstalk.com/severity/
Django Version: 3.0.8
Python Version: 3.6.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'main']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/opt/python/current/app/main/views.py", line 62, in severity
results = severity_model(image, mask)
File "/opt/python/current/app/main/ml_models.py", line 11, in severity_model
return Image_based_severity_prediction.run_model(image, mask)
File "/opt/python/current/app/main/Image_based_severity_prediction.py", line 70, in run_model
model_eff = EfficientNet.from_pretrained('efficientnet-b0')
File "/opt/python/run/venv/local/lib/python3.6/site-packages/efficientnet_pytorch/model.py", line 211, in from_pretrained
load_pretrained_weights(model, model_name, load_fc=(num_classes == 1000), advprop=advprop)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/efficientnet_pytorch/utils.py", line 327, in load_pretrained_weights
state_dict = model_zoo.load_url(url_map_[model_name])
File "/opt/python/run/venv/local/lib64/python3.6/site-packages/torch/hub.py", line 480, in load_state_dict_from_url
os.makedirs(model_dir)
File "/opt/python/run/venv/lib64/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/opt/python/run/venv/lib64/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/opt/python/run/venv/lib64/python3.6/os.py", line 210, in makedirs
makedirs(head, mode, exist_ok)
File "/opt/python/run/venv/lib64/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
Exception Type: PermissionError at /severity/
Exception Value: [Errno 13] Permission denied: '/home/wsgi'
导致此问题的文件中的代码为:
model_eff = EfficientNet.from_pretrained('efficientnet-b0')
如果很重要...
**wsgi.py**
import os
import sys
from django.core.wsgi import get_wsgi_application
# path = '/opt/python/current/app/mysite'
# if path not in sys.path:
# sys.path.append(path)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
os.environ['HTTPS'] = "on"
print("I AM IN THE GOOD FILE!!!!!!!!!!")
application = get_wsgi_application()
settings.py
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'l@q&!z!*#^b_v83bkcbxc2q0c_zk#w=9_6oz9pp38p#!-r&$!1'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['django-env.eba-au7pkejq.us-west-2.elasticbeanstalk.com', '127.0.0.1',
'django-env-3-oclock.eba-3bakdn28.us-west-2.elasticbeanstalk.com',
'http://django-env-3-oclock.eba-3bakdn28.us-west-2.elasticbeanstalk.com/',
'radiograph-models-env.eba-ctu2dpmp.us-east-1.elasticbeanstalk.com',
'radiology-ai-env.eba-wgmpba4k.us-west-2.elasticbeanstalk.com']
TINYMCE_DEFAULT_CONFIG = {
'height': 360,
'width': 1120,
'cleanup_on_startup': True,
'custom_undo_redo_levels': 20,
'selector': 'textarea',
'theme': 'modern',
'plugins': '''
textcolor save link image media preview codesample contextmenu
table code lists fullscreen insertdatetime nonbreaking
contextmenu directionality searchreplace wordcount visualblocks
visualchars code fullscreen autolink lists charmap print hr
anchor pagebreak
''',
'toolbar1': '''
fullscreen preview bold italic underline | fontselect,
fontsizeselect | forecolor backcolor | alignleft alignright |
aligncenter alignjustify | indent outdent | bullist numlist table |
| link image media | codesample |
''',
'toolbar2': '''
visualblocks visualchars |
charmap hr pagebreak nonbreaking anchor | code |
''',
'contextmenu': 'formats | link image',
'menubar': True,
'statusbar': True,
}
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'main'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.csrf'
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'EST'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join (BASE_DIR, 'static')
MEDIA_URL = 'media/'
答案 0 :(得分:1)
似乎您的割炬软件包正在尝试创建目录,但它没有写访问权限,因此权限被拒绝错误。我无法确切说出它在哪里尝试创建目录(似乎在根目录下,即/ home / wsgi)。
我建议,如果您有权访问此os.makedirs(model_dir)
,请创建一个tmp
目录,将其权限更改为777(chmod -R 777 tmp
),然后将您的model_dir
指向tmp目录(即path_to_temp/tmp/home/wsgi
)
或者您可以在root用户中创建一个目录并更改其权限。(我不确定,但是我认为它可以解决问题)
$ mkdir /home
$ chmod -R 777 /home