Skip to main content

A requests.Session that proxies through a FlareSolverr instance.

Project description

FlareSolverr Session

PyPI version CI codecov

A requests.Session that transparently routes all HTTP requests through a FlareSolverr instance, allowing you to bypass Cloudflare protection with a familiar Python API.

The project ships with a RPC client for direct access to the FlareSolverr JSON API, and a command-line interface (CLI) for quick requests and session management.

This project is not responsible for solving challenges itself, it only forwards requests to FlareSolverr. If FlareSolverr fails to solve a challenge, it will raise an exception. Any issues related to challenge solving should be reported to the FlareSolverr project.

Installation

pip install flaresolverr-session

or

pip install flaresolverr-cli

Prerequisites

You need a running FlareSolverr instance. The quickest way is via Docker:

docker run -d --name=flaresolverr -p 8191:8191 ghcr.io/flaresolverr/flaresolverr:latest

Usage

Basic Usage

from flaresolverr_session import Session

with Session("http://localhost:8191/v1") as session:
    response = session.get("https://example.com")
    print(response.status_code)
    print(response.text)

It is recommended to set a persistent session_id.

session = Session(
    "http://localhost:8191/v1",
    session_id="my-persistent-session",
)

Response Object

A FlareSolverr object is attached to the response as response.flaresolverr. It contains metadata about the request and challenge solving process returned by FlareSolverr.

Attribute Description
flaresolverr.status "ok" on success
flaresolverr.message Message from FlareSolverr (e.g. challenge status)
flaresolverr.user_agent User-Agent used by FlareSolverr's browser
flaresolverr.start / flaresolverr.end Request timestamps (ms)
flaresolverr.version FlareSolverr server version

Exception Handling

Exception Description
FlareSolverrError Base exception. Inherits from requests.exceptions.RequestException.
FlareSolverrChallengeError Challenge could not be solved.
FlareSolverrCaptchaError CAPTCHA detected. Inherits from FlareSolverrChallengeError.
FlareSolverrTimeoutError Request timed out.
FlareSolverrSessionError Session creation/destruction failed.
FlareSolverrUnsupportedMethodError Unsupported HTTP method or content type.

Command-Line Interface

After installation, you can use the flaresolverr-cli command. It is a convenient CLI tool to send HTTP requests through FlareSolverr and manage sessions.

It will output json response from FlareSolverr. If the FlareSolverr URL is not provided via -f, it will use the FLARESOLVERR_URL environment variable (defaulting to http://localhost:8191/v1).

Sending requests

The request command is the default — you can omit the word request:

flaresolverr-cli https://example.com -o output.html

# GET with a custom FlareSolverr URL
flaresolverr-cli -f http://localhost:8191/v1 https://example.com

# POST with form data (data implies POST)
flaresolverr-cli https://example.com -d "key=value&foo=bar"

Managing sessions

# Create a session (auto-generated name)
flaresolverr-cli -f http://localhost:8191/v1 session create my-session

# List all active sessions
flaresolverr-cli session list

# Destroy a session
flaresolverr-cli session destroy my-session

RPC Tool

The flaresolverr_rpc module provides a programmatic interface to the FlareSolverr JSON API, useful when you need low-level access to the raw API responses.

from flaresolverr_rpc import RPC

with RPC("http://localhost:8191/v1") as rpc:
    # Session management
    rpc.session.create(session_id="my-session", proxy="http://proxy:8080")
    sessions = rpc.session.list()
    print(sessions["sessions"])

    # HTTP requests
    result = rpc.request.get("https://example.com", session_id="my-session")
    print(result["solution"]["url"])
    print(result["solution"]["response"])  # HTML body

    result = rpc.request.post(
        "https://example.com",
        data="key=value",
        session_id="my-session",
    )

    # Cleanup
    rpc.session.destroy("my-session")

All methods return the raw JSON response dict from FlareSolverr.

Limitations

  • Only GET and application/x-www-form-urlencoded POST are supported. Otherwise, it will raise FlareSolverrUnsupportedMethodError.
  • Headers returned by FlareSolverr may be empty for some sites, depending on the FlareSolverr version and configuration. Empty HTTP status will be regarded as 200. See FlareSolverr#1162.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flaresolverr_cli-0.2.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flaresolverr_cli-0.2.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file flaresolverr_cli-0.2.0.tar.gz.

File metadata

  • Download URL: flaresolverr_cli-0.2.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for flaresolverr_cli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5bcecdfa92444578ee95938ac68839f8b3a779691a9103cb771567e7d4fce43a
MD5 3670f55750ed63a2ec61b32ef9d15f0d
BLAKE2b-256 d7a02d6a6b53d83e6961492eedabcfae6e0b36fb71d057b3d424a05171865dca

See more details on using hashes here.

File details

Details for the file flaresolverr_cli-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flaresolverr_cli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4723b17dd034a32dae5140118d6732e2487bca34118ba1c1c87626f0be6966e8
MD5 4b537e4b68f7d2011efc08ca22127f0f
BLAKE2b-256 1b9fc5e9505982f3a6bc5670fb66a9c9e8298df6114ac071bcfa8beb2f4e22ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page