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

bpo-36094: Fix a bug in smtplib module #11998

Closed
wants to merge 2 commits into from
Closed

bpo-36094: Fix a bug in smtplib module #11998

wants to merge 2 commits into from

Conversation

Tyrone-Zhao
Copy link

@Tyrone-Zhao Tyrone-Zhao commented Feb 23, 2019

The following bug occurs when you connect after creating an instance of SMTP_SSL:

import smtplib


smtp_server = "smtp.163.com"
con2 = smtplib.SMTP_SSL()
con2.connect(smtp_server, 465)

ValueError:
server_hostname cannot be an empty string or start with a leading dot.
File "E:\code\noUse.py", line 8, in
con2.connect(smtp_server, 465)

1
2
3
4
5

https://bugs.python.org/issue36094

@Tyrone-Zhao Tyrone-Zhao requested a review from a team as a code owner February 23, 2019 17:57
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

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

Good PR, please consider my comment.

Please sign CLA

Lib/smtplib.py Outdated
@@ -1038,7 +1038,7 @@ def _get_socket(self, host, port, timeout):
new_socket = socket.create_connection((host, port), timeout,
self.source_address)
new_socket = self.context.wrap_socket(new_socket,
server_hostname=self._host)
server_hostname=host)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the correct way is adding on __init__() the self._host = host

Copy link
Author

Choose a reason for hiding this comment

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

I don't think so. Cause you make a instance first, the host get "" all the time. I think the best way it's put the "self._host = host" in the connect() function. I'll try for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is probably a better solution than setting _host for the instance. Most of the connect and _get_socket methods take the host and port as input and use that instead of the one defined in the class and from that point-of-view, the use of self._host seems like a bug here.

Copy link
Contributor

@maxking maxking left a comment

Choose a reason for hiding this comment

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

I think it would be better to change the use of self._host to host, like the first commit to this PR.

Please also add a NEWS file.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella
Copy link
Contributor

@Tyrone-Zhao please address the code review from @maxking. Thank you!

@amcgregor
Copy link

It's October. Is this going to be corrected? Passing host/port at initialization time is unacceptable and unworkable, as the time of configuration is widely divorced from the time of connection, lazily on the first delivery attempt. And repeatedly, as the pool churns through workers and needs to re-connect when reaching pipelining limits. The next major will issue a warning on any SMTP use, as a deprecated interface, but that's ancillary.

prrvchr added a commit to prrvchr/cpython that referenced this pull request Nov 24, 2020
This update was made to meet 2 needs:

- Bug Fix: python#11998
- Allow backward compatibility with Python 2.7.9 or higher.
prrvchr added a commit to prrvchr/cpython that referenced this pull request Dec 3, 2020
prrvchr added a commit to prrvchr/cpython that referenced this pull request Dec 3, 2020
@vstinner vstinner closed this May 3, 2021
@vstinner vstinner deleted the branch python:master May 3, 2021 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants