当前位置:   article > 正文

最新claude逆向,使用curl_cffi 绕过指纹识别

curl_cffi
  1. import json
  2. import time
  3. from curl_cffi import requests
  4. # 定义代理服务器的地址
  5. proxy_url = "http://127.0.0.1:33210"
  6. # 构建代理字典,键是协议(http、https等),值是代理服务器地址
  7. proxies = {
  8. "http": proxy_url,
  9. "https": proxy_url
  10. }
  11. class Claude:
  12. def __init__(self,org_uuid,con_uuid,cookie):
  13. self.org_uuid = org_uuid
  14. self.con_uuid = con_uuid
  15. self.cookie = cookie
  16. def send_message(self, query):
  17. # sentry_trace = self.ctx.call('Sentry_Trace')
  18. # traceid = sentry_trace.split("-")[0]
  19. url = "https://claude.ai/api/append_message"
  20. payload = json.dumps({
  21. "completion": {
  22. "prompt": f"{query}",
  23. "timezone": "Asia/Kolkata",
  24. "model": "claude-2"
  25. },
  26. "organization_uuid": f"{self.org_uuid}",
  27. "conversation_uuid": f"{self.con_uuid}",
  28. "text": f"{query}",
  29. "attachments": []
  30. })
  31. headers = {
  32. 'User-Agent':
  33. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
  34. 'Accept': 'text/event-stream, text/event-stream',
  35. 'Accept-Language': 'en-US,en;q=0.5',
  36. 'Referer': 'https://claude.ai/chats',
  37. 'Content-Type': 'application/json',
  38. 'Origin': 'https://claude.ai',
  39. 'DNT': '1',
  40. 'Connection': 'keep-alive',
  41. 'Cookie': f'{self.cookie}',
  42. 'Sec-Fetch-Dest': 'empty',
  43. 'Sec-Fetch-Mode': 'cors',
  44. 'Sec-Fetch-Site': 'same-origin',
  45. 'TE': 'trailers'
  46. }
  47. try:
  48. response = requests.post(url, headers=headers, data=payload,impersonate="chrome110",proxies=proxies,timeout=400)
  49. print(response.text)
  50. except Exception as error:
  51. print(error)
  52. return False
  53. if len(response.text) >=60:
  54. return True
  55. return False
  56. def chat_conversation_history(self):
  57. url = f"https://claude.ai/api/organizations/{self.org_uuid}/chat_conversations/{self.con_uuid}"
  58. headers = {
  59. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
  60. 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
  61. 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  62. 'Referer': 'https://claude.ai/chats',
  63. 'Content-Type': 'application/json',
  64. 'Sec-Fetch-Dest': 'empty',
  65. 'Sec-Fetch-Mode': 'cors',
  66. 'Sec-Fetch-Site': 'same-origin',
  67. 'Connection': 'keep-alive',
  68. 'Cookie': f'{self.cookie}'
  69. }
  70. response = requests.get( url, headers=headers, proxies =proxies,impersonate="chrome110")
  71. response.encoding = 'utf-8'
  72. return response.json()
  73. def get_last_answer(history,cache):
  74. max_index = 0
  75. for i in history["chat_messages"]:
  76. if i["index"] > max_index:
  77. max_index = i["index"]
  78. body = i
  79. if max_index not in cache:
  80. cache.append(max_index)
  81. answer = body["text"]
  82. return answer,cache
  83. return None,cache
  84. def main(org_uuid,con_uuid,cookie):
  85. claude = Claude(org_uuid, con_uuid,cookie)
  86. cache = []
  87. while True:
  88. query = input("human:")
  89. result = claude.send_message(query)
  90. if result:
  91. print("send success")
  92. else:
  93. continue
  94. try_time_current = 0
  95. #最大重试次数
  96. try_time_max = 5
  97. while True:
  98. history = claude.chat_conversation_history()
  99. answer,cache = get_last_answer(history, cache)
  100. print("cache :" ,cache)
  101. if answer == None or answer == query:
  102. time.sleep(1)
  103. try_time_current += 1
  104. if try_time_current > try_time_max:
  105. answer = "消息获取失败"
  106. break
  107. continue
  108. else:
  109. break
  110. print("robot: ", answer)
  111. if __name__ == '__main__':
  112. #org_uuid= ###测试时取消注释
  113. #con_uuid= ###
  114. #cookie = ###
  115. # claude = Claude(org_uuid, con_uuid,cookie)
  116. main(org_uuid,con_uuid,cookie)

测试背景:

1.使用浏览器原生重放功能可实现重放,排除参数加密等因素。

排除api本身问题,定位到浏览器指纹上。

curl_cffi具体使用方法 再此链接curl_cffi (curl-cffi.readthedocs.io)

原始文章链接在这 原创打造 Claude网页 接口_Resphalios的博客-CSDN博客

claude对接微信的项目在这 Claude对接微信(附源码)_Resphalios的博客-CSDN博客

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/541889
推荐阅读
相关标签
  

闽ICP备14008679号