7
7
8
8
import numpy as np
9
9
import requests
10
+ from requests .adapters import HTTPAdapter
11
+ from urllib3 .util .retry import Retry
10
12
from PIL import Image
11
13
from sewar .full_ref import sam , uqi
12
14
from skimage import io
13
15
14
- requests .adapters .DEFAULT_RETRIES = 10 # 增加重连次数
15
- s = requests .session ()
16
- s .keep_alive = False # 关闭多余连接
16
+ # requests.adapters.DEFAULT_RETRIES = 10 # 增加重连次数
17
+ # s = requests.session()
18
+ # s.keep_alive = False # 关闭多余连接
19
+
20
+ session = requests .Session ()
21
+ retry = Retry (connect = 5 , backoff_factor = 0.5 )
22
+ adapter = HTTPAdapter (max_retries = retry )
23
+ session .mount ('http://' , adapter )
24
+ session .mount ('https://' , adapter )
17
25
18
26
dir = os .getcwd () + '/src/'
19
27
@@ -78,7 +86,7 @@ def get_star_count_with_np(morning_star_url):
78
86
module_path = os .getcwd () + '/src'
79
87
temp_star_url = module_path + '/assets/star/tmp.gif'
80
88
try :
81
- r = requests .get (morning_star_url )
89
+ r = session .get (morning_star_url )
82
90
except BaseException :
83
91
raise BaseException ('请求失败' )
84
92
with open (temp_star_url , "wb" ) as f :
@@ -98,10 +106,10 @@ def get_star_count_with_np(morning_star_url):
98
106
def get_star_count (morning_star_url , fund_code , img_ele = None ):
99
107
# path = './assets/star/star'
100
108
try :
101
- return get_star_count_with_sewar ( fund_code , img_ele )
109
+ return get_star_count_with_np ( morning_star_url )
102
110
except BaseException :
103
- print ('图片相似度比较失败 ' )
104
- return get_star_count_with_np ( morning_star_url )
111
+ print ('图片比较失败 ' )
112
+ return get_star_count_with_sewar ( fund_code , img_ele )
105
113
106
114
def parse_csv (datafile ):
107
115
data = []
0 commit comments