【发布时间】:2016-08-03 14:00:49
【问题描述】:
我想处理http.client.BadStatusLine: '' 异常。
我在python3上。我的代码是
import http.client
try:
req = urllib.request.Request(url, headers={'User-Agent': 'Chrome/51'})
html = urllib.request.urlopen(req).read()
soup = BeautifulSoup(html,"html.parser")
return soup
except http.client.HTTPException as eror:
print("Boom")
我读了stackOverFloeQuestion 和this,但没听懂。有什么帮助吗?
【问题讨论】:
-
在文档中:docs.python.org/3/library/… 您收到的实际错误是什么?
-
@DeepSpace。我想捕捉这个异常。这就对了。上图中红色符号表示
HTTPException未定义。 -
复制粘贴代码不会重现该问题。
-
复制粘贴?对不起 。你没看懂这个问题。 @Hans然后解决它。谢谢。
标签: python python-3.x