Python请求详细的ConnectionError处理

时间:2018-03-17 04:08:44

标签: python exception python-requests

我刚刚写了这个:

try:
    r = requests.get('http://example.com')
except requests.exceptions.ConnectionError as e:
    print(e)

我得到了这个输出:

('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

有谁知道我怎么能得到不同类型的连接错误?就像'连接中止','连接被拒绝'和'连接重置'来自这个异常并处理它们?

1 个答案:

答案 0 :(得分:0)

如果您的目标是获取响应消息然后处理它们。您可以尝试此代码。

ValueError: Expected 2D array, got 1D array instead:
array=[list([3.6368636083818036e-14, 3.392522830189899e-12, 9.89834613253366e-15, 1.2248850677983348e-12, 1.3550523047368496e-15, 3.5267405094168456e-13, 1.0774177675897417e-15, 2.7373831147145047e-13])
 list([1.2702936994261183e-07, 1.1302366112093968e-08, 3.601247032753103e-07, 1.2610271278453322e-06, 3.8544108074754034e-07, 3.7388057888913323e-07, 1.0565146699133778e-06, 3.4632712456302423e-07])
 list([6.663127039198243e-09, 1.592855782829962e-08, 2.5189316052885216e-09, 8.71344955078468e-08, 1.560205602695966e-08, 1.8025334695989781e-07, 1.1457211528200937e-06, 5.950518479674942e-07])
 ...
 list([1.8681641214886276e-08, 2.205503463622159e-08, 9.327746218326714e-10, 3.1025040738394077e-09, 2.5949152371447647e-09, 1.512181130670229e-11, 5.786442161657287e-10, 1.4137420397921863e-10])
 list([1.173538500657531e-05, 2.0979757955014606e-05, 0.00041950915503583496, 0.0005116279917528409, 0.0003344955721068041, 0.0003088865534818541, 0.0009895311928082445, 0.0008824911646422847])
 list([2.8243472997407836e-06, 4.503534390316763e-07, 6.076586515867012e-07, 3.1616543548189114e-07, 3.145241529895121e-07, 1.7389540865566907e-07, 1.7234379120699387e-07, 3.603187075520089e-08])].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.