擅长:python、mysql、java
<p>这个<code>HTTPError</code><a href="https://docs.python.org/3/library/urllib.error.html#urllib.error.HTTPError" rel="nofollow noreferrer">is a file-like object</a>。你可以捕捉它,然后<code>read</code>它的内容。</p>
<pre><code>try:
resp = urllib2.urlopen(url)
contents = resp.read()
except urllib2.HTTPError, error:
contents = error.read()
</code></pre>