Skip to content
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

FileNotFoundError: [Errno 2] No such file or directory: '' (short issue description) when using the IAM authentication mode #343

Closed
prashidi opened this issue Aug 2, 2024 · 3 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@prashidi
Copy link

prashidi commented Aug 2, 2024

Describe the bug

When trying to use the Sample provided for pub/sub with IAM authorization, I receive this error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 615, in tls_set
    f = open(certfile, "r")
        ^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/prashidi/workspace/aws/iot/iot-test-publish/publish.py", line 19, in <module>
    myAWSIoTMQTTClient.configureCredentials("./certificates/AmazonRootCA1.pem")
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 246, in configureCredentials
    self._mqtt_core.configure_cert_credentials(cert_credentials_provider, cipher_provider)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 132, in configure_cert_credentials
    self._internal_async_client.set_cert_credentials_provider(cert_credentials_provider, ciphers_provider)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py", line 86, in set_cert_credentials_provider
    self._paho_client.tls_set(ca_certs=ca_path,certfile=cert_path, keyfile=key_path,
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 617, in tls_set
    raise IOError(certfile+": "+err.strerror)
OSError: : No such file or directory
prashidi@c889f3a91d4f iot-test-publish % 
prashidi@c889f3a91d4f iot-test-publish % 
prashidi@c889f3a91d4f iot-test-publish % 
prashidi@c889f3a91d4f iot-test-publish % 
prashidi@c889f3a91d4f iot-test-publish % python3 publish.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 615, in tls_set
    f = open(certfile, "r")
        ^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/prashidi/workspace/aws/iot/iot-test-publish/publish.py", line 19, in <module>
    myAWSIoTMQTTClient.configureCredentials("certificates/AmazonRootCA1.pem")
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 246, in configureCredentials
    self._mqtt_core.configure_cert_credentials(cert_credentials_provider, cipher_provider)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 132, in configure_cert_credentials
    self._internal_async_client.set_cert_credentials_provider(cert_credentials_provider, ciphers_provider)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py", line 86, in set_cert_credentials_provider
    self._paho_client.tls_set(ca_certs=ca_path,certfile=cert_path, keyfile=key_path,
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 617, in tls_set
    raise IOError(certfile+": "+err.strerror)
OSError: : No such file or directory

Expected Behavior

The same code sample work for X.509 certificate authentication mode. However, I want to avoid the mTLS with the X.509 certificate

Current Behavior

Not working just throw the error: OSError: : No such file or directory while the certificate exist in that path

Reproduction Steps

Code sample I used:

import AWSIoTPythonSDK.MQTTLib as AWSIoTPyMQTT
import json
import time as t
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
# Define ENDPOINT, CLIENT_ID, PATH_TO_CERT, PATH_TO_KEY, PATH_TO_ROOT, MESSAGE, TOPIC, and RANGE
ENDPOINT = "endpoint-ats.iot.us-east-1.amazonaws.com"
CLIENT_ID = "a1b23cd45e"
# PATH_TO_CERT = "certificates/device.pem.crt"
# PATH_TO_KEY = "certificates/private.pem.key"
PATH_TO_ROOT = "certificates/AmazonRootCA1.pem"
AccessKeyId = "AAAAAAAAAAAAAA"
SecretKey = "DLFJLDJFLDJFLDJFLDJFLDFD"
MESSAGE = "Hello World"
TOPIC = "test/testing"
RANGE = 20
myAWSIoTMQTTClient = AWSIoTPyMQTT.AWSIoTMQTTClient(CLIENT_ID)
myAWSIoTMQTTClient.configureEndpoint(ENDPOINT, 443)
myAWSIoTMQTTClient.configureCredentials("certificates/AmazonRootCA1.pem")
myAWSIoTMQTTClient.configureIAMCredentials(AccessKeyId, SecretKey)

# myAWSIoTMQTTClient.configureCredentials(PATH_TO_ROOT, PATH_TO_KEY, PATH_TO_CERT)
myAWSIoTMQTTClient.connect()
print('Begin Publish')
for i in range(RANGE):
    data = "{} [{}]".format(MESSAGE, i+1)
    message = {"message": data}
    myAWSIoTMQTTClient.publish(TOPIC, json.dumps(message), 1)
    print("Published: '" + json.dumps(message) +
          "' to the topic: " + "'test/testing'")
    t.sleep(0.1)
print('Publish End')
myAWSIoTMQTTClient.disconnect()

You can just run this code sample with python3 fileName

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v1.5.4 Latest

Environment details (OS name and version, etc.)

MacBook macOS 14.5

@prashidi prashidi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 2, 2024
@bretambrose
Copy link
Contributor

Did you try enabling websockets?

https://github.com/aws/aws-iot-device-sdk-python/blob/master/samples/basicPubSub/basicPubSub_CognitoSTS.py#L75

@prashidi
Copy link
Author

prashidi commented Aug 2, 2024

Copy link

github-actions bot commented Aug 2, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants