This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: NNTP: add post_message wrapper to post Email Message objects
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, pitrou, r.david.murray, sobczyk
Priority: normal Keywords: patch

Created on 2013-11-25 12:28 by sobczyk, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
nntp_test.py sobczyk, 2013-11-25 13:08
Pull Requests
URL Status Linked Edit
PR 18061 closed corona10, 2020-01-19 06:56
Messages (10)
msg204331 - (view) Author: Szymon Sobik (sobczyk) Date: 2013-11-25 12:28
post method fails because string methods have bytesrting arguments

ie.
line = line.rstrip(b"\r\n") + _CRLF
msg204336 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-25 12:43
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.
msg204342 - (view) Author: Szymon Sobik (sobczyk) Date: 2013-11-25 13:08
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
msg204346 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-25 13:15
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
msg204347 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-25 13:18
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.
msg204348 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-25 13:20
It might be worth adding a post_message method, analogous to the send_message method I added to smtplib.
msg204349 - (view) Author: Szymon Sobik (sobczyk) Date: 2013-11-25 13:30
Ok I found this out too on my own.

It might be better to add examples using the MIME* classes to nntplib documentation.
msg339874 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-10 16:30
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!
msg339879 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2019-04-10 18:49
I do, and sure.  I won't be able to review it, though :(
msg339981 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-11 14:47
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.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 63969
2020-01-19 06:56:33corona10setkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request17455
2019-04-11 14:47:18cheryl.sabellasetversions: + Python 3.8, - Python 3.2, Python 3.3, Python 3.4
title: NNTP.post broken -> NNTP: add post_message wrapper to post Email Message objects
messages: + msg339981

type: behavior -> enhancement
stage: needs patch
2019-04-10 22:06:17vstinnersetnosy: - vstinner
2019-04-10 18:49:44r.david.murraysetmessages: + msg339879
2019-04-10 16:30:26cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg339874
2013-11-25 13:30:18sobczyksetmessages: + msg204349
2013-11-25 13:20:11r.david.murraysetmessages: + msg204348
2013-11-25 13:18:33r.david.murraysetmessages: + msg204347
2013-11-25 13:15:31pitrousetmessages: + msg204346
2013-11-25 13:08:29sobczyksetfiles: + nntp_test.py

messages: + msg204342
2013-11-25 12:43:49r.david.murraysetnosy: + r.david.murray, pitrou
messages: + msg204336
2013-11-25 12:31:16vstinnersetnosy: + vstinner
2013-11-25 12:28:44sobczykcreate