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

import json
import time
from curl_cffi import requests

# 定义代理服务器的地址
proxy_url = "http://127.0.0.1:33210"

# 构建代理字典,键是协议(http、https等),值是代理服务器地址
proxies = {
    "http": proxy_url,
    "https": proxy_url
}
class Claude:
    def __init__(self,org_uuid,con_uuid,cookie):
        self.org_uuid = org_uuid
        self.con_uuid = con_uuid
        self.cookie = cookie

    def send_message(self, query):
        # sentry_trace = self.ctx.call('Sentry_Trace')
        # traceid = sentry_trace.split("-")[0]
        url = "https://claude.ai/api/append_message"
        payload = json.dumps({
            "completion": {
                "prompt": f"{query}",
                "timezone": "Asia/Kolkata",
                "model": "claude-2"
            },
            "organization_uuid": f"{self.org_uuid}",
            "conversation_uuid": f"{self.con_uuid}",
            "text": f"{query}",
            "attachments": []
        })
        headers = {
            'User-Agent':
                'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
            'Accept': 'text/event-stream, text/event-stream',
            'Accept-Language': 'en-US,en;q=0.5',
            'Referer': 'https://claude.ai/chats',
            'Content-Type': 'application/json',
            'Origin': 'https://claude.ai',
            'DNT': '1',
            'Connection': 'keep-alive',
            'Cookie': f'{self.cookie}',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'TE': 'trailers'
        }

        try:
            response = requests.post(url, headers=headers, data=payload,impersonate="chrome110",proxies=proxies,timeout=400)
            print(response.text)
        except Exception as error:
            print(error)
            return False

        if len(response.text) >=60:
            return True
        return False

    def chat_conversation_history(self):
        url = f"https://claude.ai/api/organizations/{self.org_uuid}/chat_conversations/{self.con_uuid}"

        headers = {
            "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",
            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
            'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'Referer': 'https://claude.ai/chats',
            'Content-Type': 'application/json',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'Connection': 'keep-alive',
            'Cookie': f'{self.cookie}'
        }

        response = requests.get( url, headers=headers, proxies =proxies,impersonate="chrome110")
        response.encoding = 'utf-8'
        return response.json()

def get_last_answer(history,cache):

    max_index = 0
    for i in history["chat_messages"]:
        if i["index"] > max_index:
            max_index = i["index"]
            body = i
    if max_index not in cache:
        cache.append(max_index)
        answer = body["text"]
        return answer,cache
    return None,cache

def main(org_uuid,con_uuid,cookie):

    claude = Claude(org_uuid, con_uuid,cookie)
    cache = []
    while True:
        query = input("human:")

        result = claude.send_message(query)
        if result:
            print("send success")
        else:
            continue

        try_time_current = 0

        #最大重试次数
        try_time_max = 5

        while True:

            history = claude.chat_conversation_history()
            answer,cache = get_last_answer(history, cache)
            print("cache :" ,cache)
            if answer == None or answer == query:
                time.sleep(1)
                try_time_current += 1
                if try_time_current > try_time_max:
                    answer = "消息获取失败"
                    break
                continue

            else:
                break

        print("robot: ", answer)



if __name__ == '__main__':

    #org_uuid= ###测试时取消注释
    #con_uuid= ###
    #cookie = ###
    # claude = Claude(org_uuid, con_uuid,cookie)








    main(org_uuid,con_uuid,cookie)

测试背景:

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

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

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

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

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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值