Как запустить опубликованный запрос в приложении Django, развернутом на Elastic Beanstalk? - PullRequest
1 голос
/ 15 апреля 2019

Я написал приложение Django для запроса базы данных Pubmed с помощью инструмента Entrez, предоставляемого пакетом Biopython.Все работает локально.После развертывания на AWS Elastic Beanstalk я получаю «Отказано в доступе».

Я предполагаю, что проблема может заключаться в том, что Entrez пишет в каталог кэша, от которого Elastic Beanstalk отказывается.Поэтому я попытался определить каталог кеша в Entrez.esearch (db = 'pubmed', ... cache = 'tmp /') - безуспешно.

Я также пытался изменить разрешения на 'tmp' (см. Ниже .ebextensions).

Это функция в python для выполнения запроса:

    def PCMsearch(self, query, duration):
        Entrez.email = '***'
        handle = Entrez.esearch(db='pubmed',
                                sort='relevance',
                                retmax='5',
                                retmode='xml',
                                reldate = 365*duration,
                                term=query
                                directory='/tmp',
                                cache='/tmp',
                                )
        self.results = Entrez.read(handle)

        return self.results

ЛюбойПомощь высоко ценится!

Это ответ в Firefox:

Request Method: GET
Request URL: http://necessary.news/pubmed/

Django Version: 2.1
Python Version: 3.6.7
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'users.apps.UsersConfig',
 'keywords',
 'pubmed',
]
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:

File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/python/current/app/pubmed/views.py" in search_pubmed
  8.     results = query.search_pubmed()

File "/opt/python/current/app/pubmed/models.py" in search_pubmed
  63.         request = Pubmed.PCMsearch(self, keyword_list, last)

File "/opt/python/current/app/pubmed/models.py" in PCMsearch
  32.         self.results = Entrez.read(handle)

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/__init__.py" in read
  463.     record = handler.read(handle)

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in read
  378.             self.parser.ParseFile(handle)

File "/builddir/build/BUILD/Python-3.6.7/Modules/pyexpat.c" in ExternalEntityRef
  668. <source code not available>

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in externalEntityRefHandler
  808.         handle = self.open_dtd_file(filename)

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in open_dtd_file
  718.         self._initialize_directory()

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in _initialize_directory
  841.                 self.directory = os.path.join(home, '.config', 'biopython')

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in directory
  870.         self._initialize_directory()

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in _initialize_directory
  853.                 raise exception

File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/Parser.py" in _initialize_directory
  847.             os.makedirs(self.local_dtd_dir)  # use exist_ok=True on Python >= 3.2

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  210.             makedirs(head, mode, exist_ok)

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  210.             makedirs(head, mode, exist_ok)

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  210.             makedirs(head, mode, exist_ok)

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  210.             makedirs(head, mode, exist_ok)

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  210.             makedirs(head, mode, exist_ok)

File "/opt/python/run/venv/lib64/python3.6/os.py" in makedirs
  220.         mkdir(name, mode)

Exception Type: PermissionError at /pubmed/
Exception Value: [Errno 13] Permission denied: '/home/wsgi'

И это журнал ошибок в Elastic Beanstalk:

[Mon Apr 15 10:54:01.892232 2019] [:error] [pid 23822] Internal Server Error: /pubmed/
[Mon Apr 15 10:54:01.892266 2019] [:error] [pid 23822] Traceback (most recent call last):
[Mon Apr 15 10:54:01.892269 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
[Mon Apr 15 10:54:01.892272 2019] [:error] [pid 23822]     response = get_response(request)
[Mon Apr 15 10:54:01.892274 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
[Mon Apr 15 10:54:01.892278 2019] [:error] [pid 23822]     response = self.process_exception_by_middleware(e, request)
[Mon Apr 15 10:54:01.892280 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
[Mon Apr 15 10:54:01.892284 2019] [:error] [pid 23822]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Mon Apr 15 10:54:01.892286 2019] [:error] [pid 23822]   File "/opt/python/current/app/pubmed/views.py", line 8, in search_pubmed
[Mon Apr 15 10:54:01.892289 2019] [:error] [pid 23822]     results = query.search_pubmed()
[Mon Apr 15 10:54:01.892291 2019] [:error] [pid 23822]   File "/opt/python/current/app/pubmed/models.py", line 63, in search_pubmed
[Mon Apr 15 10:54:01.892293 2019] [:error] [pid 23822]     request = Pubmed.PCMsearch(self, keyword_list, last)
[Mon Apr 15 10:54:01.892296 2019] [:error] [pid 23822]   File "/opt/python/current/app/pubmed/models.py", line 28, in PCMsearch
[Mon Apr 15 10:54:01.892298 2019] [:error] [pid 23822]     term=query
[Mon Apr 15 10:54:01.892300 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/__init__.py", line 220, in esearch
[Mon Apr 15 10:54:01.892303 2019] [:error] [pid 23822]     return _open(cgi, variables)
[Mon Apr 15 10:54:01.892305 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/__init__.py", line 545, in _open
[Mon Apr 15 10:54:01.892308 2019] [:error] [pid 23822]     raise exception
[Mon Apr 15 10:54:01.892310 2019] [:error] [pid 23822]   File "/opt/python/run/venv/local/lib64/python3.6/site-packages/Bio/Entrez/__init__.py", line 543, in _open
[Mon Apr 15 10:54:01.892312 2019] [:error] [pid 23822]     handle = _urlopen(cgi)
[Mon Apr 15 10:54:01.892314 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 223, in urlopen
[Mon Apr 15 10:54:01.892317 2019] [:error] [pid 23822]     return opener.open(url, data, timeout)
[Mon Apr 15 10:54:01.892320 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
[Mon Apr 15 10:54:01.892322 2019] [:error] [pid 23822]     response = meth(req, response)
[Mon Apr 15 10:54:01.892333 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response
[Mon Apr 15 10:54:01.892335 2019] [:error] [pid 23822]     'http', request, response, code, msg, hdrs)
[Mon Apr 15 10:54:01.892337 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
[Mon Apr 15 10:54:01.892339 2019] [:error] [pid 23822]     return self._call_chain(*args)
[Mon Apr 15 10:54:01.892341 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
[Mon Apr 15 10:54:01.892347 2019] [:error] [pid 23822]     result = func(*args)
[Mon Apr 15 10:54:01.892350 2019] [:error] [pid 23822]   File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default
[Mon Apr 15 10:54:01.892352 2019] [:error] [pid 23822]     raise HTTPError(req.full_url, code, msg, hdrs, fp)
[Mon Apr 15 10:54:01.892355 2019] [:error] [pid 23822] urllib.error.HTTPError: HTTP Error 500: Internal Server Error

это всеСодержание .ebextension:

option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: "necessary/wsgi.py"
  "aws:elasticbeanstalk:container:python:staticfiles":
    "/static/": "static/"

files:
   "/etc/httpd/conf.d/ssl_rewrite.conf":
        mode: "000644"
        owner: root
        group: root
        content: |
            RewriteEngine On
            <If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
            RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
            </If>

container_commands:
    01chmod:
        command: "chmod 777 /tmp"

...