You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署FlareSolverr后,Flask+Python调用报405 Method Not Allowed错误

问题解决:FlareSolverr调用出现405 Method Not Allowed错误

问题原因

你用cURL发起的是POST请求,但Python代码里误用了requests.get()(GET请求),而FlareSolverr的/v1接口仅支持POST方法,因此返回405错误。

修复代码

把requests.get()替换为requests.post(),同时用json参数自动处理数据序列化:

import requests
import time
from bs4 import BeautifulSoup

def get_parsed_page(url, delay=0.5):
    data = {
        "cmd": "request.get",
        "url": url,
        "maxTimeout": 60000
    }
    headers = {"Content-Type": "application/json"}
    time.sleep(delay)
    # 改用POST请求,用json参数自动序列化字典为JSON格式
    response = requests.post("***:8191/v1", headers=headers, json=data)
    print(response)
    return BeautifulSoup(response.text, 'lxml')

额外说明

  • 使用json=data替代data=data,requests会自动完成字典到JSON字符串的转换,同时自动适配Content-Type头
  • 原代码重复发起了两次请求,修复后仅调用一次并保存响应到变量,提升执行效率

内容的提问来源于stack exchange,提问作者user20766085

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:42:07