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

NNTP: add post_message wrapper to post Email Message objects #63969

Closed
sobczyk mannequin opened this issue Nov 25, 2013 · 11 comments
Closed

NNTP: add post_message wrapper to post Email Message objects #63969

sobczyk mannequin opened this issue Nov 25, 2013 · 11 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sobczyk
Copy link
Mannequin

sobczyk mannequin commented Nov 25, 2013

BPO 19770
Nosy @pitrou, @bitdancer, @csabella
PRs
  • bpo-19770: Update smtp.send_message to use email.message.as_bytes() #18061
  • Files
  • nntp_test.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2013-11-25.12:28:44.337>
    labels = ['3.8', 'type-feature', 'library']
    title = 'NNTP: add post_message wrapper to post Email Message objects'
    updated_at = <Date 2020-01-19.06:56:33.754>
    user = 'https://bugs.python.org/sobczyk'

    bugs.python.org fields:

    activity = <Date 2020-01-19.06:56:33.754>
    actor = 'corona10'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2013-11-25.12:28:44.337>
    creator = 'sobczyk'
    dependencies = []
    files = ['32836']
    hgrepos = []
    issue_num = 19770
    keywords = ['patch']
    message_count = 10.0
    messages = ['204331', '204336', '204342', '204346', '204347', '204348', '204349', '339874', '339879', '339981']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'r.david.murray', 'sobczyk', 'cheryl.sabella']
    pr_nums = ['18061']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19770'
    versions = ['Python 3.8']

    @sobczyk
    Copy link
    Mannequin Author

    sobczyk mannequin commented Nov 25, 2013

    post method fails because string methods have bytesrting arguments

    ie.
    line = line.rstrip(b"\r\n") + _CRLF

    @sobczyk sobczyk mannequin added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Nov 25, 2013
    @bitdancer
    Copy link
    Member

    Can you show an example of the failure, including the traceback? I would think that nttplib would be mostly operating on byte objects, and I'm sure Antoine tested posting.

    @sobczyk
    Copy link
    Mannequin Author

    sobczyk mannequin commented Nov 25, 2013

    Traceback (most recent call last):
      File "./nntp_test.py", line 23, in <module>
        s.post(msg)
      File "/usr/lib/python3.3/nntplib.py", line 909, in post
        return self._post('POST', data)
      File "/usr/lib/python3.3/nntplib.py", line 895, in _post
        if not line.endswith(_CRLF):
    TypeError: endswith first arg must be str or a tuple of str, not bytes

    @pitrou
    Copy link
    Member

    pitrou commented Nov 25, 2013

    This won't work. The post() method needs a bytes object, or something which when iterating yields bytes data. Perhaps you can try to call as_bytes() on your MIMEText object:
    http://docs.python.org/dev/library/email.message.html#email.message.Message.as_bytes

    @bitdancer
    Copy link
    Member

    as_bytes was added in 3.4. For earlier python versions, you'll have to create a BytesGenerator object and flatten the message using it to get a bytes object you can past to post.

    @bitdancer
    Copy link
    Member

    It might be worth adding a post_message method, analogous to the send_message method I added to smtplib.

    @sobczyk
    Copy link
    Mannequin Author

    sobczyk mannequin commented Nov 25, 2013

    Ok I found this out too on my own.

    It might be better to add examples using the MIME* classes to nntplib documentation.

    @csabella
    Copy link
    Contributor

    Hi David,

    You wrote:

    It might be worth adding a post_message method, analogous to the send_message method I added to smtplib.

    Do you still think this would be worthwhile to add? If so, do you think this would be a good task for someone to work on at the PyCon sprints? Thanks!

    @bitdancer
    Copy link
    Member

    I do, and sure. I won't be able to review it, though :(

    @csabella
    Copy link
    Contributor

    Thanks David! If someone is looking for an issue to work on, I'll keep this one in mind with the caveat that it won't be reviewed during the sprints. And if no one works on it at that time, then it might be a good first issue afterwards.

    I'm updating the title to reflect the request.

    @csabella csabella added the 3.8 only security fixes label Apr 11, 2019
    @csabella csabella changed the title NNTP.post broken NNTP: add post_message wrapper to post Email Message objects Apr 11, 2019
    @csabella csabella added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Apr 11, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @hugovk
    Copy link
    Member

    hugovk commented Apr 11, 2022

    I think we can close this old issue because the nntplib module is deprecated in 3.11 and set for removal in 3.13.

    See PEP 594 – Removing dead batteries from the standard library and #91217.

    @hugovk hugovk closed this as completed Apr 11, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants