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

Fixed issue for AttributeError: 'TLSConnection' object has no attribu… #252

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

dhapati2
Copy link
Contributor

Fixed issue AttributeError: 'TLSConnection' object has no attribute 'key_file'

@@ -84,7 +84,7 @@ def connect(self):
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ssl_context.options |= ssl.OP_NO_SSLv2
ssl_context.options |= ssl.OP_NO_SSLv3
if self.key_file and self.cert_file:
if getattr(self, "key_file", None) and getattr(self, "cert_file", None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide context in PR description or Code comments around when key_file and/or cert_file won't be present?

Copy link
Contributor Author

@dhapati2 dhapati2 Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before getattr() implement case: We are just checked the value of cert_file and key_file is present or not. i.e, it is throwing error with python3.12 and works with python3.11 (reference UCSM issue #250)
AttributeError: 'TLSConnection' object has no attribute 'key_file'

After we used getattr () -> to get the value of an object's attribute and if no attribute of that object is found, default value is returned, so error resolved works on both python versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test with out input for key_file ? if None is return how the rest of the code handles it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If key_file or cert_file is not defined or their values are None, the getattr() function will return None for that attribute. So, if key_file or cert_file is not set or set to None the condition in the if statement will evaluate to False, and the subsequent code block will not execute.
In our case both are defined are None so, the code block is not skipped.
So, we did fix to avoid any AttributeError in both conditions.

@t-raghu t-raghu merged commit 317e07a into CiscoUcs:master Jun 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants