You could try to do this with getcode()
from urllib
import urllib.request
print(urllib.request.urlopen("https://www.stackoverflow.com").getcode())
200
For Python 2, use
print urllib.urlopen("http://www.stackoverflow.com").getcode()
200
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…