-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoCredentialsError: Unable to locate credentials #1941
Comments
Having the same issue here. Seems the newer boto(core) is more restrictive about the credentials? |
Having this issue as well in my project https://circleci.com/gh/cloudtools/stacker/3235 |
Same here with the s3 endpoint: import boto3
BUCKET = 's3mock'
s3 = boto3.resource('s3', use_ssl=False, verify=False)
s3.create_bucket(Bucket=BUCKET)
Same goes for |
Seen somewhere (and that helped me) that temporary solution is to downgrade to |
* Pinning PyYAML to 3.13 to deal with cfn-flip pin awslabs/aws-cfn-template-flip#54 YAML was pinned in the cfn-flip package that troposphere depends on, and without this we have issues with building. * yay, they removed the pinning! awslabs/aws-cfn-template-flip#58 * Ugh, have to go back to pinning moto. getmoto/moto#1924 getmoto/moto#1941
What's the status of this issue? I'm running into I've tried freezing various other combinations of requirements without luck, so far.
Happy to contribute, but curious if someone is already working on this. edit pinning |
* Pinning PyYAML to 3.13 to deal with cfn-flip pin awslabs/aws-cfn-template-flip#54 YAML was pinned in the cfn-flip package that troposphere depends on, and without this we have issues with building. * yay, they removed the pinning! awslabs/aws-cfn-template-flip#58 * Ugh, have to go back to pinning moto. getmoto/moto#1924 getmoto/moto#1941
Try adding the environment variable
and it works fine. The combination of all of these also seems to have fixed #1596 somehow. |
Should be fixed with #1952 Feel free to reopen if there are still issues |
@spulec
Simple test pushing messages
|
@3h4x there hasn't been a release with this change yet. If you install moto from master it'll work (at least it does for me?). If you can't do that, you'll have to wait until the next version is released. |
Thanks @dargueta , that indeed fixed my problem. |
@spulec Can you please create a release with latest changes from master? |
I solved this by adding a script and a dummy credential file. Then just do You can find the solution example in my project:
content of
content of # -*- coding: utf-8 -*-
import os
src = os.path.join(os.path.dirname(__file__), "credentials")
dst = os.path.join(os.path.expanduser("~"), ".aws", "credentials")
dst_dir = os.path.dirname(dst)
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
if not os.path.exists(dst):
with open(src, "rb") as f1:
with open(dst, "wb") as f2:
s = f1.read().decode("utf-8").format(field1="aws_access_key_id", field2="aws_secret_access_key") # this is to fool git-secret
f2.write(s.encode("utf-8")) |
I am still getting the following error when trying to donwload form s3:
This is the line that is causing the error in my tests: Here is the full test:
I have tried to add these to my environment:
This is my boto version:
and I installed moto via this command from above:
|
A workaround for getmoto/moto#1941 so tests on Travis would pass
I got the same This wasn't a problem with moto in server mode, but the regular mocked s3 didn't work. |
* s3: fixed wrong etag when copying multipart objects The etag of multipart objects depends of the number of parts, when copying to the cache we should do so in the same number of parts that the original object was moved/uploaded in. Fixes part of #1410 * s3: added check on copy for equal etag * s3: added specific exception for ETag mismatch * s3: use multipart copy to preserve etags Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai> * test: add tests for etag preservation on s3 Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai> * test: requirements: use dev version moto Specifically because of this getmoto/moto#1941 Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai> * test: requirements: install dev moto without -e Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai> * test: stop using moto Turned out to be quite buggy. Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>
Can this issue be re-opened? I ran in to the same issue as OP and had to spend quiet a bit of time digging through this project's issues in order to get the example to work. Unsure why it was closed when the fix has not been released and nothing in the readme mentions the requirement of pulling from master. |
I think what we need is a new release from master. Last was on on Nov 5, 2018 but fix was merged sometime in Feb 2019 |
The error |
I think I found the issue. This looks like a new regression with 79cd1e6 If you set up your client before the mock starts, the client won't have any credentials and changing the environment variables at that point won't help (the client doesn't recheck them). The change with #2578 might start to make a fix easier, but I think this is still going to be complicated. Any client that has been created will be pointing to the existing boto3 As a workaround for now, if you set |
We're just pinning 1.3.13 until your next release. Thanks for addressing this! |
It happens again from v1.3.14 I have following version. I followed the workaround suggestion from sulec. it helps. os.environ["AWS_ACCESS_KEY_ID"] = "test" |
mgcos1231 |
Workaround works but boy, is it ugly. os.environ["AWS_ACCESS_KEY_ID"] = "test"
os.environ["AWS_SECRET_ACCESS_KEY"] = "test" |
What is the status of this issue, guys? Still using workaround way with a couple lines of "os.environ" ? |
I still get the following error message when running the example code:
This is super frustrating :( |
This seems to be desired behavior now and is even documented in the docs http://docs.getmoto.org/en/latest/docs/getting_started.html#recommended-usage |
I'm using version 1.13.16 and exporting the environment variables hasn't worked for me. |
I also got the error But I followed Very Important -- Recommended Usage Environment
|
Also getting the same problem. Unable to locate credentials even though they are in settings.py. Have latest version of moto boto3 and botocore |
@ommmr Perhaps, you could not locate them, but if located, then it may be solved (I'm expecting ...). |
I tried with
Pinning to |
stil having the same error.... |
@omonimus1 where you able to fix it - if so could you share how you fixed it? |
I am not sure if this is applicable to anyone but one my fixes was that I was initializing the boto3 client outside of my class. So when I imported that file into my Unittest, it automatically tried to initialize the client before running anything and started throwing the credentials error For example: import logging
import boto3
client = boto3.client('transcribe', region_name='us-east-1') ### Initialized outside of the class
logging.basicConfig(level=logging.INFO)
class YourFile:
def __init__(self, bucket_name, file_name) -> None:
self.bucket_name = bucket_name
self.file_name = file_name A quick remedy, if you are initializing the client like this is to import the file inside of the test function instead of at the very top def test_start_transcribe(self):
import src.your_file ## Like so
... |
It's 2023, still the issue is not fixed |
Boto throws a NoCredentialsError if a client is created before the mock starts. The workaround since 2018 has been to set environment variables with dummy AWS credentials. However this still needs to happen before any client is created, so it should be before any imports of code under test. getmoto/moto#1941
* Update load handler to latest base image * Fix tests failing on CI Boto throws a NoCredentialsError if a client is created before the mock starts. The workaround since 2018 has been to set environment variables with dummy AWS credentials. However this still needs to happen before any client is created, so it should be before any imports of code under test. getmoto/moto#1941 * Bump version
unable to locate credentials for AWS Bedrock FMs ,how to resolve this |
I'm also getting this in our CDK project - I've done so that the test class is calling a lambda handler (in totally different module), and albeit the AWS operations works nicely in the test method itself, the AWS operations done in the other module they all seem to utterly fail to the botocore.exceptions.NoCredentialsError - unable to locate credentials. |
I'm encountering the same. I have a lambda that I'm mocking and the lambda call to invoke sagemaker returns: |
See https://stackoverflow.com/q/53220953/562769 / travis log :
I get the error message
Any idea why?
Environment variables
Software Versions
The text was updated successfully, but these errors were encountered: