How to fix the Python nntplib.NNTPDataError: line too long

The following article describes how to fix Python nntplib.NNTPDataError: line too long.

I found the issue to be related to NNTPLIB, which breaks when the overview responses (during message aggregation) are longer (in bytes) than the limit set in nntplib.py.

For example, when the response received from the server for a specific mail in the _getline() function gets over the 2048 bytes, which is a default setting in _MAXLINE, the _getline() raises NNTPDataError.

This is where the _MAXLINE that is set

I found that on specific Usenet newsgroups (e.g. comp.ai.philosophy), setting _MAXLINE to 4096 or even 32768 bytes did not fix the issue.

To get the issue permanently fixed, I had to adjust the setting to 65536 bytes:

# maximal line length when calling readline(). This is to prevent
# reading arbitrary length lines. RFC 3977 limits NNTP line length to
# 512 characters, including CRLF. We have selected 2048 just to be on
# the safe side.
_MAXLINE = 65536

The nntplib.py file is found in the Python installation. On my system, the directory of Python install was in /usr/lib64/python3.6 directory, so all I needed to do was to edit the file in question and save the changes.

Btw. to find the installation folder of Python on your Linux computer, simply type:

whereis python3

or

whereis python

 

I hope this helps (it took me a while to figure this out myself)!