擅长:python、mysql、java
<p>如果请求未成功,可以使用<code>raise_for_status()</code>引发异常。你知道吗</p>
<pre><code>try:
response = requests.get(url)
# raise exception only if the request was unsuccessful
response.raise_for_status()
except HTTPError as err:
print(err)
else:
# check the exact status and do your stuff.
</code></pre>