Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ from flask import Flask, request, jsonify, Response
|
|
2 |
import requests
|
3 |
import json
|
4 |
import time
|
5 |
-
import random
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
@@ -32,24 +31,10 @@ def handle_request():
|
|
32 |
"guidance_scale": 1
|
33 |
}
|
34 |
|
35 |
-
# 从传入的 Authorization 头中随机选择一个 token
|
36 |
-
authorization_header = request.headers.get('Authorization')
|
37 |
-
if authorization_header:
|
38 |
-
# 去掉 "Bearer " 前缀并分割 token
|
39 |
-
tokens = authorization_header.replace("Bearer ", "").split(',')
|
40 |
-
if len(tokens) > 1:
|
41 |
-
selected_token = random.choice(tokens).strip()
|
42 |
-
else:
|
43 |
-
selected_token = tokens[0].strip()
|
44 |
-
# 重新格式化为 "Bearer 随机选择的token"
|
45 |
-
selected_token = f"Bearer {selected_token}"
|
46 |
-
else:
|
47 |
-
return jsonify({"error": "Unauthorized: Missing Authorization header"}), 401
|
48 |
-
|
49 |
headers = {
|
50 |
'accept': 'application/json',
|
51 |
'content-type': 'application/json',
|
52 |
-
'Authorization':
|
53 |
}
|
54 |
|
55 |
response = requests.post(new_url, headers=headers, json=new_request_body)
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
import time
|
|
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
|
|
31 |
"guidance_scale": 1
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
headers = {
|
35 |
'accept': 'application/json',
|
36 |
'content-type': 'application/json',
|
37 |
+
'Authorization': request.headers.get('Authorization')
|
38 |
}
|
39 |
|
40 |
response = requests.post(new_url, headers=headers, json=new_request_body)
|