XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update __init__.py

Server responds with forbidden when using requests. rewrited with urllib

1629b8aa
Noel Samuel <noes14155@gmail.com>
提交于

代码差异

1 个文件 +9 -8
Modified gpt4free/aiassist/__init__.py +9 -8
@@ -1,5 +1,5 @@
1 import urllib.request
1 2 import json
2 import requests
3 3
4 4
5 5 class Completion:
@@ -20,16 +20,17 @@ class Completion:
20 20 }
21 21
22 22 url = "http://43.153.7.56:8080/api/chat-process"
23 request = requests.post(url, json=json_data)
24 request.encoding = request.apparent_encoding
25 content = request.content
23 headers = {"Content-type": "application/json"}
26 24
27 response = Completion.__load_json(content)
28 return response
25 data = json.dumps(json_data).encode("utf-8")
26 req = urllib.request.Request(url, data=data, headers=headers)
27 response = urllib.request.urlopen(req)
28 content = response.read().decode()
29
30 return Completion.__load_json(content)
29 31
30 32 @classmethod
31 33 def __load_json(cls, content) -> dict:
32 decode_content = str(content.decode("utf-8"))
33 split = decode_content.rsplit("\n", 1)[1]
34 split = content.rsplit("\n", 1)[1]
34 35 to_json = json.loads(split)
35 36 return to_json