Errors in python\3.8.3\Lib\nntplib.py

Chris Angelico rosuav at gmail.com
Wed Apr 29 17:29:26 EDT 2020


On Thu, Apr 30, 2020 at 7:18 AM G Connor <neothreeeight at hotmail.com> wrote:
>
> module: python\3.8.2\Lib\nntplib.py
> lines 903-907
> -------------------------------------------
> for line in f:
>     if not line.endswith(_CRLF):
>         line = line.rstrip(b"\r\n") + _CRLF
>     if line.startswith(b'.'):
>         line = b'.' + line
> -------------------------------------------
>
> When I try to submit a Usenet post, I get this:
>
>
> Traceback (most recent call last):
>   File "D:\python\3xcode\Usenet\posting\NNTP_post.py", line 12, in <module>
>     news.post(f)
>   File "D:\python\3.8.2\lib\nntplib.py", line 918, in post
>     return self._post('POST', data)
>   File "D:\python\3.8.2\lib\nntplib.py", line 904, in _post
>     if not line.endswith(_CRLF):
> TypeError: endswith first arg must be str or a tuple of str, not bytes

The module is expecting bytes everywhere. You've passed it a text
string but it's expecting you to pass bytes. Try opening the file in
binary mode instead.

> Also, line 906:
>     if line.startswith(b'.'):
>  looks like it should be:
>     if not line.startswith(b'.'):

No, that's correct. It's doubling the dots to ensure protocol compliance.

Neither of these is a bug in the module.

ChrisA


More information about the Python-list mailing list