django - NoCredentialsError : Unable to locate credentials - python module boto3 -


i running django in python virtual environment(virtualenv). django website served apache2 amazon ec2 instance(ubuntu 16.04). use boto3 module write amazon s3.

i installed awscli , ran aws configure , set aws access keys correctly. ( know configured correctly, because $ aws s3 ls returns correct lists of s3 buckets.)

however, when try write objects s3 django application, fails producing error described in title.

i moved new instance , started using python virtual environments. before that, used work fine. have read questions on , docs aws. below stack trace.

environment:   request method: post request url: http://*******/product/4  django version: 1.10.6 python version: 3.5.2 installed applications: ('django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'abc.apps.abcdirectconfig') installed middleware: ('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/.virtualenv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner   42.             response = get_response(request)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _legacy_get_response   249.             response = self._get_response(request)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response   187.                 response = self.process_exception_by_middleware(e, request)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response   185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/django/contrib/auth/decorators.py" in _wrapped_view   23.                 return view_func(request, *args, **kwargs)  file "/home/ubuntu/abcdirect/abcdirect/views.py" in view_product   385.             s3.bucket('abccms').put_object(key=s3_file_name, body=s3_file_data)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/boto3/resources/factory.py" in do_action   520.                 response = action(self, *args, **kwargs)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/boto3/resources/action.py" in __call__   83.         response = getattr(parent.meta.client, operation_name)(**params)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/client.py" in _api_call   253.             return self._make_api_call(operation_name, kwargs)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/client.py" in _make_api_call   530.                 operation_model, request_dict)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/endpoint.py" in make_request   141.         return self._send_request(request_dict, operation_model)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/endpoint.py" in _send_request   166.         request = self.create_request(request_dict, operation_model)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/endpoint.py" in create_request   150.                                      operation_name=operation_model.name)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/hooks.py" in emit   227.         return self._emit(event_name, kwargs)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/hooks.py" in _emit   210.             response = handler(**kwargs)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/signers.py" in handler   90.         return self.sign(operation_name, request)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/signers.py" in sign   147.             auth.add_auth(request)  file "/home/ubuntu/.virtualenv/lib/python3.5/site-packages/botocore/auth.py" in add_auth   679.             raise nocredentialserror  exception type: nocredentialserror @ /product/4 exception value: unable locate credentials 

i figured out reason getting error. posting answer in case else encounters issue.

tl;dr : aws config files did not live in apache's home directory

the django app running under user www-data(apache2). when configured credentials using aws configure, settings stored in .aws/config file.

now problem was.

the .aws/configure file stored in my home directory , not in home directory of www-data(apache2),which /var/www default. when django app called boto3 module, module looking config file in /var/www/.aws/config files in /home/ubuntu/.aws/config.

simply copying relevant files /var/www/ fixed problem me.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -