V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
momo2345
V2EX  ›  问与答

clash restful api 调用失败 求大家给点思路

  •  
  •   momo2345 · 15 天前 · 553 次点击

    我想通过 python 调用 clash restful api 但是报错连接失败 大家能帮我看看是什么问题吗,找不到原因

    下面是我的 clash 配置文件和 python 代码

    参考了这个链接: https://clash.gitbook.io/doc/restful-api

    clash:

    mixed-port: 7890
    allow-lan: true
    bind-address: '*'
    mode: global
    log-level: info
    external-controller: '127.0.0.1:9090'
    secret: 29c0c9ba-1740-42c0-bb8c-dd316c5d1e4a
    

    python:

    import requests
    
    url = 'http://127.0.0.1:9090/proxies'
    secret = "29c0c9ba-1740-42c0-bb8c-dd316c5d1e4a"
    
    headers = {
        'Authorization': f'Bearer {secret}'
    }
    
    print(requests.get(url, headers=headers).json())
    

    报错: requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9090): Max retries exceeded with url: /proxies (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10580fb90>: Failed to establish a new connection: [Errno 61] Connection refused'))

    我的网络状态是正常的,clash 也能正常使用,但是 restful api 调用不了,大家有什么解决思路吗,先谢谢了

    1 条回复    2024-09-10 11:09:55 +08:00
    guanzhangzhang
        1
    guanzhangzhang  
       14 天前
    你抓包和 curl -v 看看呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   967 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 209ms · UTC 20:37 · PVG 04:37 · LAX 13:37 · JFK 16:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.