Markdown Format | JSON API | MCP Server Tool
Help on module nntplib: NAME nntplib MODULE REFERENCE https://docs.python.org/3.10/library/nntplib.html The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. DESCRIPTION An NNTP client class based on: - RFC 977: Network News Transfer Protocol - RFC 2980: Common NNTP Extensions - RFC 3977: Network News Transfer Protocol (version 2) Example: >>> from nntplib import NNTP >>> s = NNTP('news') >>> resp, count, first, last, name = s.group('comp.lang.python') >>> print('Group', name, 'has', count, 'articles, range', first, 'to', last) Group comp.lang.python has 51 articles, range 5770 to 5821 >>> resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last)) >>> resp = s.quit() >>> Here 'resp' is the server response line. Error responses are turned into exceptions. To post an article from a file: >>> f = open(filename, 'rb') # file containing article, including header >>> resp = s.post(f) >>> For descriptions of all methods, read the comments in the code below. Note that all arguments and return values representing article numbers are strings, not numbers, since they are rarely used for calculations. CLASSES builtins.Exception(builtins.BaseException) NNTPError NNTPDataError NNTPPermanentError NNTPProtocolError NNTPReplyError NNTPTemporaryError builtins.object NNTP NNTP_SSL class NNTP(builtins.object) | NNTP(host, port=119, user=None, password=None, readermode=None, usenetrc=False, timeout=<object object at 0x7fd8d893ca50>) | | # The classes themselves | | Methods defined here: | | __enter__(self) | | __exit__(self, *args) | | __init__(self, host, port=119, user=None, password=None, readermode=None, usenetrc=False, timeout=<object object at 0x7fd8d893ca50>) | Initialize an instance. Arguments: | - host: hostname to connect to | - port: port to connect to (default the standard NNTP port) | - user: username to authenticate with | - password: password to use with username | - readermode: if true, send 'mode reader' command after | connecting. | - usenetrc: allow loading username and password from ~/.netrc file | if not specified explicitly | - timeout: timeout (in seconds) used for socket connections | | readermode is sometimes necessary if you are connecting to an | NNTP server on the local machine and intend to call | reader-specific commands, such as `group'. If you get | unexpected NNTPPermanentErrors, you might need to set | readermode. | | article(self, message_spec=None, *, file=None) | Process an ARTICLE command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the article in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of article lines) | | body(self, message_spec=None, *, file=None) | Process a BODY command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the body in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of body lines) | | capabilities(self) | Process a CAPABILITIES command. Not supported by all servers. | Return: | - resp: server response if successful | - caps: a dictionary mapping capability names to lists of tokens | (for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] }) | | date(self) | Process the DATE command. | Returns: | - resp: server response if successful | - date: datetime object | | debug = set_debuglevel(self, level) | | description(self, group) | Get a description for a single group. If more than one | group matches ('group' is a pattern), return the first. If no | group matches, return an empty string. | | This elides the response code from the server, since it can | only be '215' or '285' (for xgtitle) anyway. If the response | code is needed, use the 'descriptions' method. | | NOTE: This neither checks for a wildcard in 'group' nor does | it check whether the group actually exists. | | descriptions(self, group_pattern) | Get descriptions for a range of groups. | | getcapabilities(self) | Get the server capabilities, as read by __init__(). | If the CAPABILITIES command is not supported, an empty dict is | returned. | | getwelcome(self) | Get the welcome message from the server | (this is read and squirreled away by __init__()). | If the response code is 200, posting is allowed; | if it 201, posting is not allowed. | | group(self, name) | Process a GROUP command. Argument: | - group: the group name | Returns: | - resp: server response if successful | - count: number of articles | - first: first article number | - last: last article number | - name: the group name | | head(self, message_spec=None, *, file=None) | Process a HEAD command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the headers in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of header lines) | | help(self, *, file=None) | Process a HELP command. Argument: | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of strings returned by the server in response to the | HELP command | | ihave(self, message_id, data) | Process an IHAVE command. Arguments: | - message_id: message-id of the article | - data: file containing the article | Returns: | - resp: server response if successful | Note that if the server refuses the article an exception is raised. | | last(self) | Process a LAST command. No arguments. Return as for STAT. | | list(self, group_pattern=None, *, file=None) | Process a LIST or LIST ACTIVE command. Arguments: | - group_pattern: a pattern indicating which groups to query | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of (group, last, first, flag) (strings) | | login(self, user=None, password=None, usenetrc=True) | | newgroups(self, date, *, file=None) | Process a NEWGROUPS command. Arguments: | - date: a date or datetime object | Return: | - resp: server response if successful | - list: list of newsgroup names | | newnews(self, group, date, *, file=None) | Process a NEWNEWS command. Arguments: | - group: group name or '*' | - date: a date or datetime object | Return: | - resp: server response if successful | - list: list of message ids | | next(self) | Process a NEXT command. No arguments. Return as for STAT. | | over(self, message_spec, *, file=None) | Process an OVER command. If the command isn't supported, fall | back to XOVER. Arguments: | - message_spec: | - either a message id, indicating the article to fetch | information about | - or a (start, end) tuple, indicating a range of article numbers; | if end is None, information up to the newest message will be | retrieved | - or None, indicating the current article number must be used | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of dicts containing the response fields | | NOTE: the "message id" form isn't supported by XOVER | | post(self, data) | Process a POST command. Arguments: | - data: bytes object, iterable or file containing the article | Returns: | - resp: server response if successful | | quit(self) | Process a QUIT command and close the socket. Returns: | - resp: server response if successful | | set_debuglevel(self, level) | Set the debugging level. Argument 'level' means: | 0: no debugging output (default) | 1: print commands and responses but not body text etc. | 2: also print raw lines read and sent before stripping CR/LF | | slave(self) | Process a SLAVE command. Returns: | - resp: server response if successful | | starttls(self, context=None) | Process a STARTTLS command. Arguments: | - context: SSL context to use for the encrypted connection | | stat(self, message_spec=None) | Process a STAT command. Argument: | - message_spec: article number or message id (if not specified, | the current article is selected) | Returns: | - resp: server response if successful | - art_num: the article number | - message_id: the message id | | xhdr(self, hdr, str, *, file=None) | Process an XHDR command (optional server extension). Arguments: | - hdr: the header type (e.g. 'subject') | - str: an article nr, a message id, or a range nr1-nr2 | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of (nr, value) strings | | xover(self, start, end, *, file=None) | Process an XOVER command (optional server extension) Arguments: | - start: start of range | - end: end of range | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of dicts containing the response fields | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | encoding = 'utf-8' | | errors = 'surrogateescape' class NNTPDataError(NNTPError) | NNTPDataError(*args) | | Error in response data | | Method resolution order: | NNTPDataError | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from NNTPError: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTPError: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTPError(builtins.Exception) | NNTPError(*args) | | Base class for all nntplib exceptions | | Method resolution order: | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods defined here: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors defined here: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTPPermanentError(NNTPError) | NNTPPermanentError(*args) | | 5xx errors | | Method resolution order: | NNTPPermanentError | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from NNTPError: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTPError: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTPProtocolError(NNTPError) | NNTPProtocolError(*args) | | Response does not begin with [1-5] | | Method resolution order: | NNTPProtocolError | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from NNTPError: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTPError: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTPReplyError(NNTPError) | NNTPReplyError(*args) | | Unexpected [123]xx reply | | Method resolution order: | NNTPReplyError | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from NNTPError: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTPError: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTPTemporaryError(NNTPError) | NNTPTemporaryError(*args) | | 4xx errors | | Method resolution order: | NNTPTemporaryError | NNTPError | builtins.Exception | builtins.BaseException | builtins.object | | Methods inherited from NNTPError: | | __init__(self, *args) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTPError: | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __delattr__(self, name, /) | Implement delattr(self, name). | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setattr__(self, name, value, /) | Implement setattr(self, name, value). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args class NNTP_SSL(NNTP) | NNTP_SSL(host, port=563, user=None, password=None, ssl_context=None, readermode=None, usenetrc=False, timeout=<object object at 0x7fd8d893ca50>) | | Method resolution order: | NNTP_SSL | NNTP | builtins.object | | Methods defined here: | | __init__(self, host, port=563, user=None, password=None, ssl_context=None, readermode=None, usenetrc=False, timeout=<object object at 0x7fd8d893ca50>) | This works identically to NNTP.__init__, except for the change | in default port and the `ssl_context` argument for SSL connections. | | ---------------------------------------------------------------------- | Methods inherited from NNTP: | | __enter__(self) | | __exit__(self, *args) | | article(self, message_spec=None, *, file=None) | Process an ARTICLE command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the article in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of article lines) | | body(self, message_spec=None, *, file=None) | Process a BODY command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the body in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of body lines) | | capabilities(self) | Process a CAPABILITIES command. Not supported by all servers. | Return: | - resp: server response if successful | - caps: a dictionary mapping capability names to lists of tokens | (for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] }) | | date(self) | Process the DATE command. | Returns: | - resp: server response if successful | - date: datetime object | | debug = set_debuglevel(self, level) | | description(self, group) | Get a description for a single group. If more than one | group matches ('group' is a pattern), return the first. If no | group matches, return an empty string. | | This elides the response code from the server, since it can | only be '215' or '285' (for xgtitle) anyway. If the response | code is needed, use the 'descriptions' method. | | NOTE: This neither checks for a wildcard in 'group' nor does | it check whether the group actually exists. | | descriptions(self, group_pattern) | Get descriptions for a range of groups. | | getcapabilities(self) | Get the server capabilities, as read by __init__(). | If the CAPABILITIES command is not supported, an empty dict is | returned. | | getwelcome(self) | Get the welcome message from the server | (this is read and squirreled away by __init__()). | If the response code is 200, posting is allowed; | if it 201, posting is not allowed. | | group(self, name) | Process a GROUP command. Argument: | - group: the group name | Returns: | - resp: server response if successful | - count: number of articles | - first: first article number | - last: last article number | - name: the group name | | head(self, message_spec=None, *, file=None) | Process a HEAD command. Argument: | - message_spec: article number or message id | - file: filename string or file object to store the headers in | Returns: | - resp: server response if successful | - ArticleInfo: (article number, message id, list of header lines) | | help(self, *, file=None) | Process a HELP command. Argument: | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of strings returned by the server in response to the | HELP command | | ihave(self, message_id, data) | Process an IHAVE command. Arguments: | - message_id: message-id of the article | - data: file containing the article | Returns: | - resp: server response if successful | Note that if the server refuses the article an exception is raised. | | last(self) | Process a LAST command. No arguments. Return as for STAT. | | list(self, group_pattern=None, *, file=None) | Process a LIST or LIST ACTIVE command. Arguments: | - group_pattern: a pattern indicating which groups to query | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of (group, last, first, flag) (strings) | | login(self, user=None, password=None, usenetrc=True) | | newgroups(self, date, *, file=None) | Process a NEWGROUPS command. Arguments: | - date: a date or datetime object | Return: | - resp: server response if successful | - list: list of newsgroup names | | newnews(self, group, date, *, file=None) | Process a NEWNEWS command. Arguments: | - group: group name or '*' | - date: a date or datetime object | Return: | - resp: server response if successful | - list: list of message ids | | next(self) | Process a NEXT command. No arguments. Return as for STAT. | | over(self, message_spec, *, file=None) | Process an OVER command. If the command isn't supported, fall | back to XOVER. Arguments: | - message_spec: | - either a message id, indicating the article to fetch | information about | - or a (start, end) tuple, indicating a range of article numbers; | if end is None, information up to the newest message will be | retrieved | - or None, indicating the current article number must be used | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of dicts containing the response fields | | NOTE: the "message id" form isn't supported by XOVER | | post(self, data) | Process a POST command. Arguments: | - data: bytes object, iterable or file containing the article | Returns: | - resp: server response if successful | | quit(self) | Process a QUIT command and close the socket. Returns: | - resp: server response if successful | | set_debuglevel(self, level) | Set the debugging level. Argument 'level' means: | 0: no debugging output (default) | 1: print commands and responses but not body text etc. | 2: also print raw lines read and sent before stripping CR/LF | | slave(self) | Process a SLAVE command. Returns: | - resp: server response if successful | | starttls(self, context=None) | Process a STARTTLS command. Arguments: | - context: SSL context to use for the encrypted connection | | stat(self, message_spec=None) | Process a STAT command. Argument: | - message_spec: article number or message id (if not specified, | the current article is selected) | Returns: | - resp: server response if successful | - art_num: the article number | - message_id: the message id | | xhdr(self, hdr, str, *, file=None) | Process an XHDR command (optional server extension). Arguments: | - hdr: the header type (e.g. 'subject') | - str: an article nr, a message id, or a range nr1-nr2 | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of (nr, value) strings | | xover(self, start, end, *, file=None) | Process an XOVER command (optional server extension) Arguments: | - start: start of range | - end: end of range | - file: Filename string or file object to store the result in | Returns: | - resp: server response if successful | - list: list of dicts containing the response fields | | ---------------------------------------------------------------------- | Data descriptors inherited from NNTP: | | __dict__ | dictionary for instance variables (if defined) | | __weakref__ | list of weak references to the object (if defined) | | ---------------------------------------------------------------------- | Data and other attributes inherited from NNTP: | | encoding = 'utf-8' | | errors = 'surrogateescape' FUNCTIONS decode_header(header_str) Takes a unicode string representing a munged header value and decodes it as a (possibly non-ASCII) readable value. DATA __all__ = ['NNTP', 'NNTPError', 'NNTPReplyError', 'NNTPTemporaryError'... FILE /usr/lib/python3.10/nntplib.py
Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:16 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)