0
我一直在使用Python中的requests
庫在Web服務器上查詢數據。我得到以下錯誤:正確處理連接錯誤:連接中止,BadStatusLine(「'」,)
ConnectionError: ('Connection aborted.', BadStatusLine("''",))
我想我的程序不中止,但測試連接,並從中斷的地方繼續。我應該怎麼做?
我有一個功能,下面的代碼名爲query_predix_ts
,查詢Web服務器:
r_s = requests.post(url, data=json.dumps(payload2), headers=header_store)
這裏的函數調用:
for tag in tags_list:
if tag in tags_with_dim_list:
for dim in dims:
try:
df = query_predix_ts(t1, t2, tag, 0, this_msk, dim)
except(ValueError, NameError) as e:
print e
if df.shape[0] != 0:
sensor_type = tag + dim
df['sensor_type'] = sensor_type
# print df.head()
single_df.append(df)
我應該如何包裝在try-例外內這條線所以當出現連接錯誤時,它會繼續嘗試,在中止前說5次?