if you are able to run the cli on the same box on which the python script it being run and it works, you have your iam profile setup correctly (assuming you don't have an ~/.aws/credentials file in there.
I assume this is not a container?
If not, then this is an issue likely with your code. Can you share the relevant part of your python code, as well as the python code for s3 that is working?
How to get access to s3 for .NET SDK with the same credentials used for awscli?asked 5 days ago
Cli "Unable to locate credentials" on EC2 instanceasked 5 months ago
EC2 instance metadat credentials initial delayasked 2 months ago
Botocore not able to use credentials on EC2 instanceasked 2 years ago
AWS instance end Credentialsasked 6 months ago
Credentials Changingasked 4 months ago
Getting AWS Credentials into a Docker Container without Hardcoding Itasked 5 months ago
AWS Greengrass - Boto3 credentialsasked a year ago
boto3 1.9.212 not able to create channel ChannelClass not setting upasked 3 years ago
Docker is not able to pick IAM role when running on EC2 instanceasked 8 months ago