tanbushi commited on
Commit
de54e43
·
1 Parent(s): d99260b
Files changed (1) hide show
  1. proxy.py +15 -12
proxy.py CHANGED
@@ -3,19 +3,22 @@ import httpx # 使用httpx替代requests,因为requests是同步的,而FastA
3
 
4
  async def do_proxy(url:str, method:str, headers:dict, content:str):
5
  print("Proxy service started.", url)
6
- # 使用httpx异步客户端发起请求
7
- async with httpx.AsyncClient() as client:
8
- response = await client.request(
9
- method=method,
10
- url=url,
11
- headers=headers,
12
- content=content, # httpx使用content参数传递请求体
13
- timeout=30 # 超时时间,可调整
14
- )
15
-
 
 
 
16
  # 将Gemini的响应透传给客户端
17
  return Response(
18
- content=response.content,
19
- status_code=response.status_code,
20
  headers=dict(response.headers)
21
  )
 
3
 
4
  async def do_proxy(url:str, method:str, headers:dict, content:str):
5
  print("Proxy service started.", url)
6
+ try:
7
+ # 使用httpx异步客户端发起请求
8
+ async with httpx.AsyncClient() as client:
9
+ response = await client.request(
10
+ method=method,
11
+ url=url,
12
+ headers=headers,
13
+ content=content, # httpx使用content参数传递请求体
14
+ timeout=30 # 超时时间,可调整
15
+ )
16
+ except Exception as e:
17
+ print("Error:", e)
18
+
19
  # 将Gemini的响应透传给客户端
20
  return Response(
21
+ content=response.content,
22
+ status_code=response.status_code,
23
  headers=dict(response.headers)
24
  )