<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"module-smtplib.html" />
<link rel=
"prev" href=
"module-imaplib.html" />
<link rel=
"parent" href=
"internet.html" />
<link rel=
"next" href=
"nntp-objects.html" />
<meta name='aesop' content='information'
/>
<title>11.11 nntplib -- NNTP protocol client
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.10.2 IMAP4 Example"
href=
"imap4-example.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11. Internet Protocols and"
href=
"internet.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.11.1 NNTP Objects"
href=
"nntp-objects.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"imap4-example.html">11.10.2 IMAP4 Example
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"internet.html">11. Internet Protocols and
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"nntp-objects.html">11.11.1 NNTP Objects
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION00131100000000000000000">
11.11 <tt class=
"module">nntplib
</tt> --
<A NAME=
"module-nntplib"></A>
<a id='l2h-
3453' xml:id='l2h-
3453'
></a><a id='l2h-
3461' xml:id='l2h-
3461'
></a>
This module defines the class
<tt class=
"class">NNTP
</tt> which implements the client
side of the NNTP protocol. It can be used to implement a news reader
or poster, or automated news processors. For more information on NNTP
(Network News Transfer Protocol), see Internet
<a class=
"rfc" id='rfcref-
90274' xml:id='rfcref-
90274'
href=
"http://www.faqs.org/rfcs/rfc977.html">RFC
977</a>.
Here are two small examples of how it can be used. To list some
statistics about a newsgroup and print the subjects of the last
10
<div class=
"verbatim"><pre>
>>> s = NNTP('news.cwi.nl')
>>> 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
59 articles, range
3742 to
3803
>>> resp, subs = s.xhdr('subject', first + '-' + last)
>>> for id, sub in subs[-
10:]: print id, sub
3792 Re: Removing elements from a list while iterating...
3793 Re: Who likes Info files?
3794 Emacs and doc strings
3795 a few questions about the Mac implementation
3796 Re: executable python scripts
3797 Re: executable python scripts
3798 Re: a few questions about the Mac implementation
3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules
3802 Re: executable python scripts
3803 Re: \POSIX{} wait and SIGCHLD
'
205 news.cwi.nl closing connection. Goodbye.'
To post an article from a file (this assumes that the article has
<div class=
"verbatim"><pre>
>>> s = NNTP('news.cwi.nl')
>>> f = open('/tmp/article')
'
240 Article posted successfully.'
'
205 news.cwi.nl closing connection. Goodbye.'
The module itself defines the following items:
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3454' xml:id='l2h-
3454'
class=
"class">NNTP
</tt></b>(
</nobr></td>
<td><var>host
</var><big>[
</big><var>, port
</var><big>[
</big><var>, user
</var><big>[
</big><var>, password
</var><big>[
</big><var>, readermode
</var><big>]
</big><var>
</var><big>[
</big><var>, usenetrc
</var><big>]
</big><var></var><big>]
</big><var></var><big>]
</big><var></var><big>]
</big><var></var>)
</td></tr></table></dt>
Return a new instance of the
<tt class=
"class">NNTP
</tt> class, representing a
connection to the NNTP server running on host
<var>host
</var>, listening at
port
<var>port
</var>. The default
<var>port
</var> is
119. If the optional
<var>user
</var> and
<var>password
</var> are provided,
or if suitable credentials are present in
<span class=
"file"> /.netrc
</span> and the
optional flag
<var>usenetrc
</var> is true (the default),
the
"<tt class="samp
">AUTHINFO USER</tt>" and
"<tt class="samp
">AUTHINFO PASS</tt>" commands are used to
identify and authenticate the user to the server. If the optional
flag
<var>readermode
</var> is true, then a
"<tt class="samp
">mode reader</tt>" command is
sent before authentication is performed. Reader mode is sometimes
necessary if you are connecting to an NNTP server on the local machine
and intend to call reader-specific commands, such as
"<tt class="samp
">group</tt>". If
you get unexpected
<code>NNTPPermanentError
</code>s, you might need to set
<var>readermode
</var>.
<var>readermode
</var> defaults to
<code>None
</code>.
<var>usenetrc
</var> defaults to
<code>True
</code>.
<span class=
"versionnote">Changed in version
2.4:
<var>usenetrc
</var> argument added.
</span>
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3455' xml:id='l2h-
3455'
class=
"class">NNTPError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Derived from the standard exception
<code>Exception
</code>, this is the base
class for all exceptions raised by the
<code>nntplib
</code> module.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3456' xml:id='l2h-
3456'
class=
"class">NNTPReplyError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Exception raised when an unexpected reply is received from the
server. For backwards compatibility, the exception
<code>error_reply
</code>
is equivalent to this class.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3457' xml:id='l2h-
3457'
class=
"class">NNTPTemporaryError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Exception raised when an error code in the range
400-
499 is
received. For backwards compatibility, the exception
<code>error_temp
</code> is equivalent to this class.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3458' xml:id='l2h-
3458'
class=
"class">NNTPPermanentError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Exception raised when an error code in the range
500-
599 is
received. For backwards compatibility, the exception
<code>error_perm
</code> is equivalent to this class.
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3459' xml:id='l2h-
3459'
class=
"class">NNTPProtocolError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Exception raised when a reply is received from the server that does
not begin with a digit in the range
1-
5. For backwards
compatibility, the exception
<code>error_proto
</code> is equivalent to this
<dl><dt><table cellpadding=
"0" cellspacing=
"0"><tr valign=
"baseline">
<td><nobr><b><span class=
"typelabel">class
</span> <tt id='l2h-
3460' xml:id='l2h-
3460'
class=
"class">NNTPDataError
</tt></b>(
</nobr></td>
<td><var></var>)
</td></tr></table></dt>
Exception raised when there is some error in the response data. For
backwards compatibility, the exception
<code>error_data
</code> is
equivalent to this class.
<p><br /></p><hr class='online-navigation'
/>
<div class='online-navigation'
>
<!--Table of Child-Links-->
<A NAME=
"CHILD_LINKS"><STRONG>Subsections
</STRONG></a>
<LI><A href=
"nntp-objects.html">11.11.1 NNTP Objects
</a>
<!--End of Table of Child-Links-->
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"11.10.2 IMAP4 Example"
href=
"imap4-example.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"11. Internet Protocols and"
href=
"internet.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11.11.1 NNTP Objects"
href=
"nntp-objects.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"imap4-example.html">11.10.2 IMAP4 Example
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"internet.html">11. Internet Protocols and
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"nntp-objects.html">11.11.1 NNTP Objects
</A>
<span class=
"release-info">Release
2.4.2, documentation updated on
28 September
2005.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.