Skip to content

Commit 9530825

Browse files
authored
Update rthk.py
1 parent 1ed1ad4 commit 9530825

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

code/rthk.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,40 @@ async def get_response(url, timeout=10, mustFetch=True, method='GET', session=se
248248
global total_requests, cache_hits, verCount11, verCount20, verCount30
249249
total_requests += 1
250250
while True:
251-
session.quic_cache_layer.add_domain(urllib.parse.urlparse(url).netloc)
252-
response = await asyncio.to_thread(session.request, method, url, timeout=timeout)
253-
254-
if response.from_cache:
255-
cache_hits += 1
251+
try:
252+
session.quic_cache_layer.add_domain(urllib.parse.urlparse(url).netloc)
253+
response = await asyncio.to_thread(session.request, method, url, timeout=timeout)
254+
255+
if response.from_cache:
256+
cache_hits += 1
257+
258+
if not response.from_cache and response.raw.version:
259+
if response.raw.version == 10: # fix later
260+
verCount11 += 1 # fix later
261+
if response.raw.version == 11:
262+
verCount11 += 1
263+
elif response.raw.version == 20:
264+
verCount20 += 1
265+
elif response.raw.version == 30:
266+
verCount30 += 1
267+
268+
return response
269+
270+
# except OverwhelmedTraffic as e:
271+
# print('error: OverwhelmedTraffic')
272+
# continue
256273

257-
if not response.from_cache and response.raw.version:
258-
if response.raw.version == 10: # fix later
259-
verCount11 += 1 # fix later
260-
if response.raw.version == 11:
261-
verCount11 += 1
262-
elif response.raw.version == 20:
263-
verCount20 += 1
264-
elif response.raw.version == 30:
265-
verCount30 += 1
274+
except Exception as e:
275+
# if str(e).strip() == 'Cannot select a disposable connection to ease the charge':
276+
if str(e).strip().startswith('Cannot select a disposable connection to ease the charge') or str(e).strip().startswith('Cannot memorize traffic indicator upon unknown connection'):
277+
# print('error: Cannot select a disposable connection to ease the charge, aka OverwhelmedTraffic(?)')
278+
print(f"請求 {url} 出錯: {e},嘗試重試...")
279+
280+
continue
281+
282+
else:
283+
print(f"請求 {url} 出錯: {e},嘗試重試...")
266284

267-
return response
268-
269285
if not mustFetch:
270286
break
271287

0 commit comments

Comments
 (0)