MetaMetricsInc/django-warrant

NoRegionError

Closed this issue · 2 comments

After deploying my application to AWS Elastic Beanstalk, I have been getting a NoRegionError. Everything works fine when I run my Django server locally. I am not sure if this is a bug or if I am doing something wrong. There is no mentioning of a "region_name" in the readme file.

Error Output

Environment:


Request Method: POST
Request URL: http://******************/authenticate/

Django Version: 1.11.6
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',
 'dashboard',
 'registration']
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.4/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

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

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

File "/opt/python/current/app/registration/views.py" in authentication
  54.                 user = authenticate(request, username=email, password=password)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/auth/__init__.py" in authenticate
  70.             user = _authenticate_with_backend(backend, backend_path, request, credentials)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/auth/__init__.py" in _authenticate_with_backend
  115.     return backend.authenticate(*args, **credentials)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/warrant/django/backend.py" in authenticate
  102.                 username=username, password=password)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/warrant/django/backend.py" in authenticate
  71.             username=username)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/warrant/__init__.py" in __init__
  172.         self.client = boto3.client('cognito-idp', **boto3_client_kwargs)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto3/__init__.py" in client
  83.     return _get_default_session().client(*args, **kwargs)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto3/session.py" in client
  263.             aws_session_token=aws_session_token, config=config)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/session.py" in create_client
  861.             client_config=config, api_version=api_version)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/client.py" in create_client
  76.             verify, credentials, scoped_config, client_config, endpoint_bridge)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/client.py" in _get_client_args
  288.             verify, credentials, scoped_config, client_config, endpoint_bridge)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/args.py" in get_client_args
  45.             endpoint_url, is_secure, scoped_config)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/args.py" in compute_client_args
  111.             service_name, region_name, endpoint_url, is_secure)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/client.py" in resolve
  361.             service_name, region_name)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/regions.py" in construct_endpoint
  122.                 partition, service_name, region_name)

File "/opt/python/run/venv/local/lib/python3.4/site-packages/botocore/regions.py" in _endpoint_for_partition
  135.                 raise NoRegionError()

Exception Type: NoRegionError at /authenticate/
Exception Value: You must specify a region.

@Austint30 you may have already found a solution, but I added:

import boto3
boto3.setup_default_session(region_name='us-east-1')

to my settings.py and the error went away.

Another way to solve this problem is to add AWS_DEFAULT_REGION environment