airsltd commited on
Commit
e02e6ae
·
1 Parent(s): c310793
Files changed (1) hide show
  1. proxyserver-fastapi.py +1 -48
proxyserver-fastapi.py CHANGED
@@ -82,59 +82,12 @@ async def proxy_request(url_path: str, request: Request):
82
  # 转发原始请求的头部,排除 'Host' 头部以避免冲突
83
  # FastAPI 的 request.headers 是不可变的,需要转换为字典
84
  headers = {key: value for key, value in request.headers.items() if key.lower() != 'host' and key.lower() != 'content-length'}
85
- # headers["user-agent"] = "PostmanRuntime/7.45.0"
86
 
87
  # 将检索到的第三方API密钥添加到目标API的请求头中
88
  headers["authorization"] = f"Bearer {third_party_api_key}"
89
  print(f"添加第三方API Key到请求头: Authorization: Bearer {third_party_api_key[:5]}...")
90
- print("\n\n请求头部-1: ")
91
- pretty_json = json.dumps(headers, indent=4, sort_keys=True, ensure_ascii=False)
92
- print(pretty_json)
93
-
94
-
95
-
96
- # headers={}
97
- # headers["accept"]="*/*"
98
- # headers["accept-encoding"]="gzip, deflate, br"
99
- # headers["authorization"]=f"Bearer {third_party_api_key}"
100
- # headers["content-type"]="application/json"
101
- # # headers["postman-token"]="ad3552d5-c379-4ec0-ae86-9b26cc59bb4b"
102
- headers["user-agent"]="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
103
- # headers["x-amzn-trace-id"]="Root=1-68a054e2-78a54d08502e945f387c1952"
104
- # headers["x-direct-url"]="https://airsltd-fastapi-proxy.hf.space/--replicas/pn6yq/v1/https/generativelanguage.googleapis.com/v1beta/openai/chat/completions"
105
-
106
- # headers["x-forwarded-for"]="45.144.242.202"
107
- # headers["x-forwarded-port"]="443"
108
- # headers["x-forwarded-proto"]="https"
109
- # headers["x-ip-token"]="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpcCI6IjQ1LjE0NC4yNDIuMjAyIiwidXNlciI6bnVsbCwidXVpZCI6bnVsbCwiZXJyb3IiOiJJbnZhbGlkQWNjZXNzVG9rZW4iLCJleHAiOjE3NTUzMzgwMTR9.1e-GZx1NaD0_91Bs2g0SZIAiUCSVc8g5EUHVrTGsbcE"
110
- # headers["x-request-id"]="YG7fx0"
111
-
112
 
113
- headers = {
114
- "accept": "*/*",
115
- "accept-encoding": "gzip, deflate, br",
116
- "authorization": "Bearer AIzaSyDCbN6WDNIEtB8yJmNX40ScechQu6mCZoo",
117
- "content-type": "application/json",
118
- "postman-token": "6668952f-bdad-4454-9bb8-e97553fc7678",
119
- "user-agent": "PostmanRuntime/7.45.0",
120
- "x-amzn-trace-id": "Root=1-68a06427-671a7ab91bc8f8aa370f02f1",
121
- "x-direct-url": "https://airsltd-fastapi-proxy.hf.space/--replicas/8yrch/v1/https/generativelanguage.googleapis.com/v1beta/openai/chat/completions",
122
- "x-forwarded-for": "222.125.206.179",
123
- "x-forwarded-port": "443",
124
- "x-forwarded-proto": "https",
125
- "x-ip-token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpcCI6IjIyMi4xMjUuMjA2LjE3OSIsInVzZXIiOm51bGwsInV1aWQiOm51bGwsImVycm9yIjoiSW52YWxpZEFjY2Vzc1Rva2VuIiwiZXhwIjoxNzU1MzQxOTIzfQ.G4LXLe1O6Q-VWQkj3C9aXoVe1oCRhArsXQNPxc3Wswc",
126
- "x-request-id": "--eng0"
127
- }
128
-
129
-
130
-
131
- print("\n\n请求头部-2: ")
132
- pretty_json = json.dumps(headers, indent=4, sort_keys=True, ensure_ascii=False)
133
- print(pretty_json)
134
-
135
-
136
-
137
-
138
  # 获取请求体
139
  request_body = await request.body()
140
 
 
82
  # 转发原始请求的头部,排除 'Host' 头部以避免冲突
83
  # FastAPI 的 request.headers 是不可变的,需要转换为字典
84
  headers = {key: value for key, value in request.headers.items() if key.lower() != 'host' and key.lower() != 'content-length'}
85
+ headers["user-agent"]="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
86
 
87
  # 将检索到的第三方API密钥添加到目标API的请求头中
88
  headers["authorization"] = f"Bearer {third_party_api_key}"
89
  print(f"添加第三方API Key到请求头: Authorization: Bearer {third_party_api_key[:5]}...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # 获取请求体
92
  request_body = await request.body()
93