Network News

Network News, also known as Usenet, is mostly transmitted with the Network News Transport Protocol (NNTP). The specifications of the POP protocol are at http://www.ietf.org/rfc/rfc977.txt and http://www.ietf.org/rfc/rfc2980.txt. The Python standard library supports this protocol in module nntplib. The nntplib module supplies a class NNTP to connect to an NNTP server.

NNTP

class NNTP(host, port=119, user=None, password=None, readermode=False, usenetrc=True)

Returns an instance n of class NNTP connected to the host and port, and optionally authenticated with the given user and password if user is not None. When readermode is True, also sends a 'mode reader' command; you may need this, depending on the NNTP server and on the NNTP commands you send to that server. When usenetrc is True, tries getting user and password for authentication from a file named .netrc in the current user’s home directory, if not explicitly specified.

Response Strings

An instance n of NNTP supplies many methods. Each of n’s methods returns a tuple whose first item is a string (known as response in the following), which is the response from the NNTP server to the NNTP command that corresponds to the method (method post just returns the response string, not a tuple). Each method returns the response string just as the NNTP server supplies it. The string starts with an integer in decimal form (the integer is known as the return code), followed by a space, followed by explanatory text.

For some commands, ...

Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.