What does urllib2.Request(<url>) do and how do i print/view it
<p>I'm trying to learn how urllib2 works and how it encapsulates its various components before sending out an actual request or response.</p>

<p>So far I have:-</p>

<blockquote>
  <blockquote>
    <p>theurl = "www.example.com"</p>
  </blockquote>
</blockquote>

<p>That obviously specifies the url to look at</p>

<blockquote>
  <blockquote>
    <p>req = urllib2.Request(theurl) </p>
  </blockquote>
</blockquote>

<p>Don't know what this does, hence the question</p>

<blockquote>
  <blockquote>
    <p>handle = urllib2.urlopen(req)</p>
  </blockquote>
</blockquote>

<p>This one gets the page and does all the requests and responses required.</p>

<p>So my question is, what does urllib2.Request actually do?
To try and look at it to get an idea I tried </p>

<blockquote>
  <blockquote>
    <p>print req </p>
  </blockquote>
</blockquote>

<p>and just got </p>

<blockquote>
  <blockquote>
    <p><code>&lt;urllib2.Request instance at 0x123456789&gt;</code></p>
  </blockquote>
</blockquote>

<p>I also tried</p>

<blockquote>
  <blockquote>
    <p>print req.read() </p>
  </blockquote>
</blockquote>

<p>and got:-</p>

<blockquote>
  <blockquote>
    <p>Traceback (most recent call last):<br>
        File "", line 1, in ?<br>
        File "/usr/lib64/python2.4/urllib2.py, line 207, in <code>__</code>getattr<code>__</code><br>
            raise AttributeError, attr<br>
    AttributeError: read</p>
  </blockquote>
</blockquote>

<p>So I'm obviously doing something wrong. If anyone can help in one of both my questions that would be great.</p>

<p>Thanks,</p>

<p>dog</p>
