Spaces:
Runtime error
Runtime error
Commit
·
5b59897
1
Parent(s):
264c5ec
fix
Browse files
searcher/sementic_search.py
CHANGED
|
@@ -34,25 +34,23 @@ def extract(text, type):
|
|
| 34 |
|
| 35 |
|
| 36 |
async def fetch(url):
|
| 37 |
-
await asyncio.sleep(1)
|
| 38 |
try:
|
| 39 |
timeout = aiohttp.ClientTimeout(total=120)
|
| 40 |
-
|
|
|
|
| 41 |
async with session.get(url) as response:
|
| 42 |
if response.status == 200:
|
| 43 |
content = await response.read() # Read the response content as bytes
|
| 44 |
return content
|
| 45 |
else:
|
| 46 |
-
await asyncio.sleep(0.01)
|
| 47 |
print(f"Failed to fetch the URL: {url} with status code: {response.status}")
|
| 48 |
return None
|
| 49 |
except aiohttp.ClientError as e: # 更具体的异常捕获
|
| 50 |
-
await asyncio.sleep(0.01)
|
| 51 |
print(f"An error occurred while fetching the URL: {url}")
|
| 52 |
print(e)
|
| 53 |
return None
|
| 54 |
except Exception as e:
|
| 55 |
-
await asyncio.sleep(0.01)
|
| 56 |
print(f"An unexpected error occurred while fetching the URL: {url}")
|
| 57 |
print(e)
|
| 58 |
return None
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
async def fetch(url):
|
| 37 |
+
await asyncio.sleep(1) # 异步的 sleep 而不是 time.sleep
|
| 38 |
try:
|
| 39 |
timeout = aiohttp.ClientTimeout(total=120)
|
| 40 |
+
connector = aiohttp.TCPConnector(limit_per_host=10) # 使用连接池
|
| 41 |
+
async with aiohttp.ClientSession(timeout=timeout, connector=connector) as session:
|
| 42 |
async with session.get(url) as response:
|
| 43 |
if response.status == 200:
|
| 44 |
content = await response.read() # Read the response content as bytes
|
| 45 |
return content
|
| 46 |
else:
|
|
|
|
| 47 |
print(f"Failed to fetch the URL: {url} with status code: {response.status}")
|
| 48 |
return None
|
| 49 |
except aiohttp.ClientError as e: # 更具体的异常捕获
|
|
|
|
| 50 |
print(f"An error occurred while fetching the URL: {url}")
|
| 51 |
print(e)
|
| 52 |
return None
|
| 53 |
except Exception as e:
|
|
|
|
| 54 |
print(f"An unexpected error occurred while fetching the URL: {url}")
|
| 55 |
print(e)
|
| 56 |
return None
|