USGS-WiM / whispersservices

Django services for WHISPers
2 stars 1 forks source link

error on POST to servicerequests #344

Closed lprivette closed 4 years ago

lprivette commented 4 years ago

image

JSON:

{
  "event": 170747,
  "request_type": 1,
  "new_comments": [
    {
      "comment": "Lauren test 3/6/2020",
      "comment_type": 9
    }
  ]
}

TRACEBACK:

AttributeError at /servicerequests/
'NoneType' object has no attribute 'id'

Request Method: POST
Request URL: https://whispersdev.wim.usgs.gov/whispersservices/servicerequests/
Django Version: 2.2.10
Python Executable: /usr/bin/python3
Python Version: 3.5.2
Python Path: ['/var/www/whispersservices_django', '/var/www/whispersservices_django/env/lib/python35.zip', '/var/www/whispersservices_django/env/lib/python3.5', '/var/www/whispersservices_django/env/lib/python3.5/plat-x86_64-linux-gnu', '/var/www/whispersservices_django/env/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/var/www/whispersservices_django/env/lib/python3.5/site-packages']
Server time: Fri, 6 Mar 2020 17:38:38 +0000
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'simple_history',
 'rest_framework',
 'corsheaders',
 'dry_rest_permissions',
 'whispersservices']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'simple_history.middleware.HistoryRequestMiddleware']

Traceback:

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/viewsets.py" in view
  114.             return self.dispatch(request, *args, **kwargs)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
  505.             response = self.handle_exception(exc)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/views.py" in handle_exception
  465.             self.raise_uncaught_exception(exc)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/views.py" in raise_uncaught_exception
  476.         raise exc

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/views.py" in dispatch
  502.             response = handler(request, *args, **kwargs)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/mixins.py" in create
  19.         self.perform_create(serializer)

File "/var/www/whispersservices_django/whispersservices/views.py" in perform_create
  138.             serializer.save(created_by=self.request.user, modified_by=self.request.user)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/rest_framework/serializers.py" in save
  212.             self.instance = self.create(validated_data)

File "/var/www/whispersservices_django/whispersservices/serializers.py" in create
  3866.                                            comment_type=comment_type, created_by=user, modified_by=user)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
  82.                 return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/var/www/whispersservices_django/env/lib/python3.5/site-packages/django/db/models/query.py" in create
  422.         obj.save(force_insert=True, using=self.db)

File "/var/www/whispersservices_django/whispersservices/models.py" in save
  1937.             if self.created_by.id in [hfs_epi_user.id, madison_epi_user.id]:

Exception Type: AttributeError at /servicerequests/
Exception Value: 'NoneType' object has no attribute 'id'
Request information:
USER: whisperstester

GET: No GET data

POST: No POST data

FILES: No FILES data

COOKIES: No cookie data

META:
CONTENT_LENGTH = '153'
CONTENT_TYPE = 'application/json'
CONTEXT_DOCUMENT_ROOT = '/var/www/whispersdev'
CONTEXT_PREFIX = ''
DOCUMENT_ROOT = '/var/www/whispersdev'
GATEWAY_INTERFACE = 'CGI/1.1'
HTTP_ACCEPT = '*/*'
HTTP_ACCEPT_ENCODING = 'gzip, deflate, br'
HTTP_AUTHORIZATION = 'Basic d2hpc3BlcnN0ZXN0ZXI6d2hpc3BlcnN0ZXN0ZXI='
HTTP_CACHE_CONTROL = 'no-cache'
HTTP_CONNECTION = 'keep-alive'
HTTP_HOST = 'whispersdev.wim.usgs.gov'
HTTP_POSTMAN_TOKEN = '0a64bd4d-a468-4856-8372-617215ad21b2'
HTTP_USER_AGENT = 'PostmanRuntime/7.22.0'
PATH_INFO = '/servicerequests/'
PATH_TRANSLATED = '/var/www/whispersdev/servicerequests/'
QUERY_STRING = ''
REMOTE_ADDR = '71.163.133.166'
REMOTE_PORT = '56599'
REQUEST_METHOD = 'POST'
REQUEST_SCHEME = 'https'
REQUEST_URI = '/whispersservices/servicerequests/'
SCRIPT_FILENAME = '/var/www/whispersservices_django/whispersservices_django/wsgi.py'
SCRIPT_NAME = '/whispersservices'
SERVER_ADDR = '10.0.1.14'
SERVER_ADMIN = '[no address given]'
SERVER_NAME = 'whispersdev.wim.usgs.gov'
SERVER_PORT = '443'
SERVER_PROTOCOL = 'HTTP/1.1'
SERVER_SIGNATURE = '<address>Apache/2.4.18 (Ubuntu) Server at whispersdev.wim.usgs.gov Port 443</address>\n'
SERVER_SOFTWARE = 'Apache/2.4.18 (Ubuntu)'
SSL_TLS_SNI = 'whispersdev.wim.usgs.gov'
apache.version = '(2, 4, 18)'
mod_wsgi.application_group = 'whispersdev.wim.usgs.gov|/whispersservices'
mod_wsgi.callable_object = 'application'
mod_wsgi.daemon_connects = '1'
mod_wsgi.daemon_restarts = '0'
mod_wsgi.daemon_start = '1583516317929988'
mod_wsgi.enable_sendfile = '0'
mod_wsgi.handler_script = ''
mod_wsgi.ignore_activity = '0'
mod_wsgi.listener_host = ''
mod_wsgi.listener_port = '443'
mod_wsgi.path_info = '/servicerequests/'
mod_wsgi.process_group = 'dev'
mod_wsgi.queue_start = '1583516317929867'
mod_wsgi.request_handler = 'wsgi-script'
mod_wsgi.request_id = '/lCgHxN0WXs'
mod_wsgi.request_start = '1583516317929726'
mod_wsgi.script_name = '/whispersservices'
mod_wsgi.script_reloading = '1'
mod_wsgi.script_start = '1583516317930095'
mod_wsgi.thread_id = 1
mod_wsgi.thread_requests = 60
mod_wsgi.total_requests = 428
mod_wsgi.version = '(4, 7, 1)'
wsgi.errors = <_io.TextIOWrapper name='<wsgi.errors>' encoding='utf-8'>
wsgi.file_wrapper = ''
wsgi.input = <mod_wsgi.Input object at 0x7f4343cb6420>
wsgi.input_terminated = True
wsgi.multiprocess = False
wsgi.multithread = True
wsgi.run_once = False
wsgi.url_scheme = 'https'
wsgi.version = '(1, 0)'

Settings:
Using settings module whispersservices_django.settings
ABSOLUTE_URL_OVERRIDES = {}
ADMINS = []
ADMIN_ENABLED = False
ALLOWED_HOSTS = ['whispersdev.wim.usgs.gov', '52.3.161.36', '10.0.1.14', '127.0.0.1', 'localhost']
APPEND_SLASH = True
APP_WHISPERS_URL = 'https://whispersdev.wim.usgs.gov/whispers/'
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
AUTH_PASSWORD_VALIDATORS = '********************'
AUTH_USER_MODEL = 'whispersservices.User'
BASE_DIR = '/var/www/whispersservices_django'
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}
CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_KEY_PREFIX = '********************'
CACHE_MIDDLEWARE_SECONDS = 600
CELERY_BROKER_URL = 'amqp://localhost'
CELERY_IMPORTS = ['whispersservices.immediate_tasks', 'whispersservices.scheduled_tasks']
CELERY_RESULT_BACKEND = 'rpc://'
CONFIG = <configparser.RawConfigParser object at 0x7f434dcfd0f0>
CORS_ORIGIN_ALLOW_ALL = True
CSRF_COOKIE_AGE = 31449600
CSRF_COOKIE_DOMAIN = None
CSRF_COOKIE_HTTPONLY = False
CSRF_COOKIE_NAME = 'csrftoken'
CSRF_COOKIE_PATH = '/'
CSRF_COOKIE_SAMESITE = 'Lax'
CSRF_COOKIE_SECURE = False
CSRF_FAILURE_VIEW = 'django.views.csrf.csrf_failure'
CSRF_HEADER_NAME = 'HTTP_X_CSRFTOKEN'
CSRF_TRUSTED_ORIGINS = []
CSRF_USE_SESSIONS = False
DATABASES = {'default': {'PORT': '5432', 'HOST': 'nwhc.ck2zppz9pgsw.us-east-1.rds.amazonaws.com', 'TIME_ZONE': None, 'CONN_MAX_AGE': 60, 'OPTIONS': {}, 'AUTOCOMMIT': True, 'TEST': {'CHARSET': None, 'COLLATION': None, 'NAME': None, 'MIRROR': None}, 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ATOMIC_REQUESTS': False, 'PASSWORD': '********************', 'NAME': 'whispersdev', 'USER': 'nwhcadmin'}}
DATABASE_ROUTERS = []
DATA_UPLOAD_MAX_MEMORY_SIZE = 2621440
DATA_UPLOAD_MAX_NUMBER_FIELDS = 1000
DATETIME_FORMAT = 'N j, Y, P'
DATETIME_INPUT_FORMATS = ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S.%f', '%Y-%m-%d %H:%M', '%Y-%m-%d', '%m/%d/%Y %H:%M:%S', '%m/%d/%Y %H:%M:%S.%f', '%m/%d/%Y %H:%M', '%m/%d/%Y', '%m/%d/%y %H:%M:%S', '%m/%d/%y %H:%M:%S.%f', '%m/%d/%y %H:%M', '%m/%d/%y']
DATE_FORMAT = 'N j, Y'
DATE_INPUT_FORMATS = ['%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', '%b %d %Y', '%b %d, %Y', '%d %b %Y', '%d %b, %Y', '%B %d %Y', '%B %d, %Y', '%d %B %Y', '%d %B, %Y']
DEBUG = True
DEBUG_PROPAGATE_EXCEPTIONS = False
DECIMAL_SEPARATOR = '.'
DEFAULT_CHARSET = 'utf-8'
DEFAULT_CONTENT_TYPE = 'text/html'
DEFAULT_EXCEPTION_REPORTER_FILTER = 'django.views.debug.SafeExceptionReporterFilter'
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
DEFAULT_FROM_EMAIL = 'whispers@usgs.gov'
DEFAULT_INDEX_TABLESPACE = ''
DEFAULT_TABLESPACE = ''
DISALLOWED_USER_AGENTS = []
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.usgs.gov'
EMAIL_HOST_PASSWORD = '********************'
EMAIL_HOST_USER = 'whispers@usgs.gov'
EMAIL_NWHC_EPI = 'nwhc-epi@usgs.gov'
EMAIL_PORT = '25'
EMAIL_SSL_CERTFILE = None
EMAIL_SSL_KEYFILE = '********************'
EMAIL_SUBJECT_PREFIX = '[Django] '
EMAIL_TIMEOUT = 180
EMAIL_USE_LOCALTIME = False
EMAIL_USE_SSL = False
EMAIL_USE_TLS = True
EMAIL_WHISPERS = 'whispers@usgs.gov'
ENVIRONMENT = 'development'
FILE_CHARSET = 'utf-8'
FILE_UPLOAD_DIRECTORY_PERMISSIONS = None
FILE_UPLOAD_HANDLERS = ['django.core.files.uploadhandler.MemoryFileUploadHandler', 'django.core.files.uploadhandler.TemporaryFileUploadHandler']
FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440
FILE_UPLOAD_PERMISSIONS = None
FILE_UPLOAD_TEMP_DIR = None
FIRST_DAY_OF_WEEK = 0
FIXTURE_DIRS = []
FORCE_SCRIPT_NAME = None
FORMAT_MODULE_PATH = None
FORM_RENDERER = 'django.forms.renderers.DjangoTemplates'
GEONAMES_USERNAME = 'nwhcwhispers'
IGNORABLE_404_URLS = []
INSTALLED_APPS = ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'simple_history', 'rest_framework', 'corsheaders', 'dry_rest_permissions', 'whispersservices']
INTERNAL_IPS = []
LANGUAGES = [('af', 'Afrikaans'), ('ar', 'Arabic'), ('ast', 'Asturian'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('dsb', 'Lower Sorbian'), ('el', 'Greek'), ('en', 'English'), ('en-au', 'Australian English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-co', 'Colombian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy', 'Frisian'), ('ga', 'Irish'), ('gd', 'Scottish Gaelic'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hsb', 'Upper Sorbian'), ('hu', 'Hungarian'), ('hy', 'Armenian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('io', 'Ido'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kab', 'Kabyle'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('mr', 'Marathi'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmål'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('vi', 'Vietnamese'), ('zh-hans', 'Simplified Chinese'), ('zh-hant', 'Traditional Chinese')]
LANGUAGES_BIDI = ['he', 'ar', 'fa', 'ur']
LANGUAGE_CODE = 'en-us'
LANGUAGE_COOKIE_AGE = None
LANGUAGE_COOKIE_DOMAIN = None
LANGUAGE_COOKIE_NAME = 'django_language'
LANGUAGE_COOKIE_PATH = '/'
LOCALE_PATHS = []
LOGGING = {}
LOGGING_CONFIG = 'logging.config.dictConfig'
LOGIN_REDIRECT_URL = '/accounts/profile/'
LOGIN_URL = '/accounts/login/'
LOGOUT_REDIRECT_URL = None
MANAGERS = []
MEDIA_ROOT = '/var/www/whispersservices_django/media'
MEDIA_URL = '/media/'
MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
MIDDLEWARE = ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'simple_history.middleware.HistoryRequestMiddleware']
MIGRATION_MODULES = {}
MONTH_DAY_FORMAT = 'F j'
NUMBER_GROUPING = 0
PASSWORD_HASHERS = '********************'
PASSWORD_RESET_TIMEOUT_DAYS = '********************'
PREPEND_WWW = False
PROJECT_PATH = '/var/www/whispersservices_django'
REST_FRAMEWORK = {'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.SessionAuthentication')}
ROOT_URLCONF = 'whispersservices_django.urls'
SECRET_KEY = '********************'
SECURE_BROWSER_XSS_FILTER = False
SECURE_CONTENT_TYPE_NOSNIFF = False
SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SECURE_HSTS_PRELOAD = False
SECURE_HSTS_SECONDS = 0
SECURE_PROXY_SSL_HEADER = None
SECURE_REDIRECT_EXEMPT = []
SECURE_SSL_HOST = None
SECURE_SSL_REDIRECT = False
SERVER_EMAIL = 'root@localhost'
SESSION_CACHE_ALIAS = 'default'
SESSION_COOKIE_AGE = 1209600
SESSION_COOKIE_DOMAIN = None
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_NAME = 'sessionid'
SESSION_COOKIE_PATH = '/'
SESSION_COOKIE_SAMESITE = 'Lax'
SESSION_COOKIE_SECURE = False
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_FILE_PATH = None
SESSION_SAVE_EVERY_REQUEST = False
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
SETTINGS_DIR = '/var/www/whispersservices_django/whispersservices_django'
SETTINGS_MODULE = 'whispersservices_django.settings'
SHORT_DATETIME_FORMAT = 'm/d/Y P'
SHORT_DATE_FORMAT = 'm/d/Y'
SIGNING_BACKEND = 'django.core.signing.TimestampSigner'
SILENCED_SYSTEM_CHECKS = []
SSL_CERT = '/var/www/whispersservices_django/whispersservices_django/ca-bundle.crt'
STATICFILES_DIRS = "('/var/www/whispersservices_django/static/staticfiles',)"
STATICFILES_FINDERS = ['django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder']
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STATIC_PATH = '/var/www/whispersservices_django/static/staticfiles'
STATIC_ROOT = '/var/www/whispersservices_django/static'
STATIC_URL = '/static/'
TEMPLATES = [{'DIRS': ['/var/www/whispersservices_django/templates'], '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']}, 'BACKEND': 'django.template.backends.django.DjangoTemplates'}]
TEMPLATE_PATH = '/var/www/whispersservices_django/templates'
TEST_NON_SERIALIZED_APPS = []
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
THOUSAND_SEPARATOR = ','
TIME_FORMAT = 'P'
TIME_INPUT_FORMATS = ['%H:%M:%S', '%H:%M:%S.%f', '%H:%M']
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_THOUSAND_SEPARATOR = False
USE_TZ = True
USE_X_FORWARDED_HOST = False
USE_X_FORWARDED_PORT = False
WSGI_APPLICATION = 'whispersservices_django.wsgi.application'
X_FRAME_OPTIONS = 'SAMEORIGIN'
YEAR_MONTH_FORMAT = 'F Y'

You're seeing this error because you have DEBUG = True in your
Django settings file. Change that to False, and Django will
display a standard page generated by the handler for this status code.
aaronstephenson commented 4 years ago

Fixed. The code was expecting a particular user, who didn't happen to be in the users table.