Amazon + Django every 12 hours appears that [Errno 5] I / O Error

I recently installed and deployed an instance of Amazon EC2 to deploy my django project.

I interacted with my application through the browser when I get this error in the browser:

errno 5 input/output error django

enter image description here

This error referred to some functions of my application.

Environment:

Request Method: GET
Request URL: http://localhost:8000/accounts/profile/

Django Version: 1.9
Python Version: 3.4.3
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'crispy_forms',
 'django_extensions',
 'storages',
 'userprofile']
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.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/views/generic/base.py" in view
  68.             return self.dispatch(request, *args, **kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/home/ubuntu/workspace/neurorehabilitation-system/userprofile/mixins.py" in dispatch
  7.         return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/views/generic/base.py" in dispatch
  88.         return handler(request, *args, **kwargs)

File "/home/ubuntu/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/views/generic/base.py" in get
  157.         context = self.get_context_data(**kwargs)

File "/home/ubuntu/workspace/neurorehabilitation-system/userprofile/views.py" in get_context_data
  50.             print (user.is_physiotherapist)

Exception Type: OSError at /accounts/profile/
Exception Value: [Errno 5] Input/output error

At the end of line 50 is a function get_context_data()that is inside a class-based view that inherits TemplateViewCBV

but in my console, the server requires a reboot, and when I did this, the error was resolved in a magical way.

I looked for this error and I found that this ticket reported https://code.djangoproject.com/ticket/23284

This report is very similar to my mistake ...

, , , .

- EC2 Django ( ), ?

, get_context_data() ...

+4
2

, ,

:

  • print

, , print get_context_data() :

File "/home/ubuntu/workspace/neurorehabilitation-system/userprofile/views.py" in get_context_data
  50.             print (user.is_physiotherapist)

, , , stdout amazon ec2.

git gunicorn, .

  1. DEBUG=True

:

settings/
    base.py # --- without DEBUG
    development.py # --- DEBUG=True
    testing.py # --- DEBUG=True
    production.py # --- DEBUG=False
    staging.py # --- DEBUG=False  

(development.py, testing.py, production.py, staging.py) base.py

, ec2, execute.py , base.py DEBUG False.

, (True False) , ,

(nrb_dev)ubuntu@ip-172-31-27-249:~$ python
Python 3.4.3 (default, Oct 14 2015, 20:28:29) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> a=socket.gethostname()
>>> a
'ip-172-31-27-249'
>>> 
>>> if a != 'ip-172-31-27-249':
...     DEBUG = print ('Caleno juiciocito')
... 
>>> DEBUG
True
>>> 

, base.py :

import socket

if socket.gethostname() == 'ip-172-31-27-249':
    DEBUG = False
else:
    DEBUG = True

. , thar , ,

, , ?

, , , , - DJANGO_SETTINGS_MODULE

virtualenvwrapper, , :

nrb_dev

nrb_test . , .

nrb_dev $VIRTUAL_ENV/bin/postactivate :

export DJANGO_SETTINGS_MODULE="neurorehabilitation.settings.development"

, nrb_test $VIRTUAL_ENV/bin/postactivate :

export DJANGO_SETTINGS_MODULE="neurorehabilitation.settings.testing"

, Amazon EC2 $VIRTUAL_ENV/bin/postactivate, settings/production.py :

export DJANGO_SETTINGS_MODULE="neurorehabilitation.settings.production"

DEBUG settings/production.py

from .base import *

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
print (DEBUG) # just for now.

-, , DEBUG False

(nrb_dev)ubuntu@ip-172-31-27-249:~/workspace/neurorehabilitation-system$ gunicorn -c neurorehabilitation/gunicorn_config.py neurorehabilitation.wsgi 
[2016-01-08 00:26:15 +0000] [6691] [INFO] Starting gunicorn 19.4.5
[2016-01-08 00:26:15 +0000] [6691] [INFO] Listening at: http://127.0.0.1:8000 (6691)
[2016-01-08 00:26:15 +0000] [6691] [INFO] Using worker: sync
[2016-01-08 00:26:15 +0000] [6694] [INFO] Booting worker with pid: 6694
False
^C[2016-01-08 00:26:19 +0000] [6691] [INFO] Handling signal: int

Django .

, .

:

Ubuntu

Django Nginx, Gunicorn, virtualenv, supervisor PostgreSQL

+4

"./my_api/to/Credit.py", 17, get_credit_from_response

print xml_response

. get_credit_from_response - -. , 6/12 . .

+1

Source: https://habr.com/ru/post/1623157/


All Articles