返回提交历史
Modified
g4f/Provider/DDG.py
+8
-6
XFEstudio/gpt4free
fix: fix DDG ERR_CHALLENGE
- [fix] Replace "x-vqd-hash-1" header extraction with random hash in g4f/Provider/DDG.py - [refactor] Adjust conditional to return generated hash when vqd exists in g4f/Provider/DDG.py - [fix] Prevent updating conversation.vqd_hash_1 from response headers to avoid ERR_CHALLENGE
56c3661c
代码差异
1 个文件
+8
-6
@@ -118,13 +118,14 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
118
118
await raise_for_status(response)
119
119
120
120
vqd = response.headers.get("x-vqd-4", "")
121
vqd_hash_1 = response.headers.get("x-vqd-hash-1", "")
122
121
123
if vqd and vqd_hash_1:
124
return vqd, vqd_hash_1
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
125
126
126
if vqd and not vqd_hash_1:
127
return vqd, ""
127
if vqd:
128
return vqd, vqd_hash_1
128
129
129
130
response_text = await response.text()
130
131
raise RuntimeError(f"Failed to fetch VQD token and hash: {response.status} {response_text}")
@@ -238,7 +239,8 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
238
239
if return_conversation:
239
240
conversation.message_history.append({"role": "assistant", "content": full_message})
240
241
conversation.vqd = response.headers.get("x-vqd-4", conversation.vqd)
241
conversation.vqd_hash_1 = response.headers.get("x-vqd-hash-1", conversation.vqd_hash_1)
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)
242
244
conversation.cookies = {
243
245
n: c.value
244
246
for n, c in session.cookie_jar.filter_cookies(URL(cls.url)).items()