返回提交历史
Modified
g4f/Provider/DDG.py
+5
-11
XFEstudio/gpt4free
fix: DDG ERR_CHALLENGE header handling
- [fix] Remove random vqd_hash_1 generation in g4f/Provider/DDG.py (lines 118-120) - [fix] Fetch x-vqd-hash-1 header directly in g4f/Provider/DDG.py instead of using random data - [fix] Ensure conversation.vqd_hash_1 always updates to address ERR_CHALLENGE (lines 239+)
ac4c380d
代码差异
1 个文件
+5
-11
@@ -118,13 +118,11 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
118
118
await raise_for_status(response)
119
119
120
120
vqd = response.headers.get("x-vqd-4", "")
121
122
# Generate a random string for vqd_hash_1 instead of getting it from response headers
123
letters = "abcdefghijklmnopqrstuvwxyz"
124
random_hash = ''.join(random.choice(letters) for _ in range(7))
125
vqd_hash_1 = random_hash
121
# Fetch the actual hash from the response header
122
vqd_hash_1 = response.headers.get("x-vqd-hash-1", "")
126
123
127
124
if vqd:
125
# Return the fetched vqd and vqd_hash_1
128
126
return vqd, vqd_hash_1
129
127
130
128
response_text = await response.text()
@@ -179,11 +177,8 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
179
177
"origin": "https://duckduckgo.com",
180
178
"referer": "https://duckduckgo.com/",
181
179
"x-vqd-4": conversation.vqd,
180
"x-vqd-hash-1": "",
182
181
}
183
184
# Add the x-vqd-hash-1 header if available
185
if conversation.vqd_hash_1:
186
headers["x-vqd-hash-1"] = conversation.vqd_hash_1
187
182
188
183
data = {
189
184
"model": model,
@@ -239,8 +234,7 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
239
234
if return_conversation:
240
235
conversation.message_history.append({"role": "assistant", "content": full_message})
241
236
conversation.vqd = response.headers.get("x-vqd-4", conversation.vqd)
242
# Don't update vqd_hash_1 from response headers to avoid ERR_CHALLENGE
243
# conversation.vqd_hash_1 = response.headers.get("x-vqd-hash-1", conversation.vqd_hash_1)
237
conversation.vqd_hash_1 = response.headers.get("x-vqd-hash-1", conversation.vqd_hash_1)
244
238
conversation.cookies = {
245
239
n: c.value
246
240
for n, c in session.cookie_jar.filter_cookies(URL(cls.url)).items()