llzai commited on
Commit
fd831ef
·
verified ·
1 Parent(s): 6dba2a2

Upload 11 files

Browse files
Files changed (7) hide show
  1. .dockerignore +45 -0
  2. DEPLOY_HF.md +196 -0
  3. Dockerfile +4 -4
  4. README.md +99 -267
  5. README_bak.md +257 -0
  6. api_solver.py +36 -7
  7. docker-compose.yml +3 -3
.dockerignore ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ venv/
8
+ env/
9
+ ENV/
10
+ .venv
11
+
12
+ # IDE
13
+ .vscode/
14
+ .idea/
15
+ *.swp
16
+ *.swo
17
+ *~
18
+
19
+ # Git
20
+ .git/
21
+ .gitignore
22
+
23
+ # Docker
24
+ Dockerfile
25
+ .dockerignore
26
+
27
+ # Documentation
28
+ README.md
29
+ *.md
30
+
31
+ # Logs
32
+ *.log
33
+
34
+ # Database
35
+ *.db
36
+ *.sqlite
37
+ *.sqlite3
38
+
39
+ # OS
40
+ .DS_Store
41
+ Thumbs.db
42
+
43
+ # Temporary files
44
+ *.tmp
45
+ *.temp
DEPLOY_HF.md ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Spaces 部署指南
2
+
3
+ 本指南将帮助您将 Turnstile Solver 部署到 Hugging Face Spaces。
4
+
5
+ ## 📋 前提条件
6
+
7
+ 1. 拥有 Hugging Face 账号
8
+ 2. 已安装 Git
9
+
10
+ ## 🚀 部署步骤
11
+
12
+ ### 1. 创建新的 Space
13
+
14
+ 1. 访问 [Hugging Face Spaces](https://huggingface.co/spaces)
15
+ 2. 点击 "Create new Space"
16
+ 3. 填写以下信息:
17
+ - **Space name**: 您的项目名称(例如:turnstile-solver)
18
+ - **License**: MIT
19
+ - **Select the Space SDK**: Docker
20
+ - **Space hardware**: CPU basic(免费)或更高配置
21
+ 4. 点击 "Create Space"
22
+
23
+ ### 2. 准备文件
24
+
25
+ 确保您的项目包含以下文件:
26
+
27
+ ```
28
+ .
29
+ ├── Dockerfile # Docker 配置文件
30
+ ├── api_solver.py # 主程序文件
31
+ ├── browser_configs.py # 浏览器配置
32
+ ├── db_results.py # 数据库操作
33
+ ├── requirements.txt # Python 依赖
34
+ ├── proxies.txt # 代理列表(可选)
35
+ └── README_HF.md # HF Spaces 说明文档(重命名为 README.md)
36
+ ```
37
+
38
+ ### 3. 上传到 Hugging Face
39
+
40
+ #### 方法 A: 使用 Git(推荐)
41
+
42
+ ```bash
43
+ # 克隆您的 Space 仓库
44
+ git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
45
+ cd YOUR_SPACE_NAME
46
+
47
+ # 复制项目文件到仓库
48
+ cp /path/to/your/project/* .
49
+
50
+ # 重命名 README_HF.md 为 README.md
51
+ mv README_HF.md README.md
52
+
53
+ # 提交并推送
54
+ git add .
55
+ git commit -m "Initial deployment"
56
+ git push
57
+ ```
58
+
59
+ #### 方法 B: 使用 Web 界面
60
+
61
+ 1. 在 Space 页面点击 "Files and versions"
62
+ 2. 点击 "Add file" > "Upload files"
63
+ 3. 上传所有必需的文件
64
+ 4. 确保将 `README_HF.md` 重命名为 `README.md`
65
+
66
+ ### 4. 配置 Space
67
+
68
+ 在 Space 的设置中:
69
+
70
+ 1. **Hardware**:
71
+ - 免费版:CPU basic(2 vCPU, 16GB RAM)
72
+ - 推荐:CPU upgrade(8 vCPU, 32GB RAM)用于更好的性能
73
+
74
+ 2. **Environment variables**(可选):
75
+ - 如果需要,可以添加环境变量
76
+
77
+ ### 5. 等待部署
78
+
79
+ - Space 会自动构建 Docker 镜像
80
+ - 首次构建可能需要 5-10 分钟
81
+ - 构建完成后,服务会自动启动
82
+ - 浏览器池初始化需要额外 30-60 秒
83
+
84
+ ### 6. 验证部署
85
+
86
+ 部署完成后,访问以下端点验证:
87
+
88
+ ```bash
89
+ # 健康检查
90
+ curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/health
91
+
92
+ # 就绪检查
93
+ curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/ready
94
+
95
+ # 主页
96
+ https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/
97
+ ```
98
+
99
+ ## 🔧 配置选项
100
+
101
+ ### 修改浏览器线程数
102
+
103
+ 在 `Dockerfile` 中修改启动命令:
104
+
105
+ ```dockerfile
106
+ CMD ["python", "api_solver.py", "--host", "0.0.0.0", "--port", "7860", "--thread", "8"]
107
+ ```
108
+
109
+ ### 启用代理支持
110
+
111
+ 1. 在 `proxies.txt` 中添加代理
112
+ 2. 修改 `Dockerfile` 启动命令:
113
+
114
+ ```dockerfile
115
+ CMD ["python", "api_solver.py", "--host", "0.0.0.0", "--port", "7860", "--proxy", "--random"]
116
+ ```
117
+
118
+ ### 启用调试模式
119
+
120
+ ```dockerfile
121
+ CMD ["python", "api_solver.py", "--host", "0.0.0.0", "--port", "7860", "--debug"]
122
+ ```
123
+
124
+ ## 📊 监控和日志
125
+
126
+ ### 查看日志
127
+
128
+ 1. 在 Space 页面点击 "Logs"
129
+ 2. 查看实时日志输出
130
+ 3. 检查浏览器初始化状态
131
+
132
+ ### 常见日志消息
133
+
134
+ - `"Application startup completed, browser initialization in progress..."` - 服务已启动,浏览器正在初始化
135
+ - `"Browser pool initialized and ready to accept requests"` - 服务完全就绪
136
+ - `"Successfully solved captcha"` - 成功解决验证码
137
+
138
+ ## ⚠️ 注意事项
139
+
140
+ 1. **启动时间**:
141
+ - 服务启动后需要 30-60 秒初始化浏览器池
142
+ - 在此期间,API 请求会返回 503 错误
143
+ - 使用 `/ready` 端点检查就绪状态
144
+
145
+ 2. **资源限制**:
146
+ - 免费版 CPU 可能导致性能较慢
147
+ - 建议使用 CPU upgrade 以获得更好性能
148
+
149
+ 3. **超时设置**:
150
+ - HF Spaces 有 60 秒的请求超时限制
151
+ - 确保验证码求解在此时间内完成
152
+
153
+ 4. **持久化存储**:
154
+ - Space 重启后数据会丢失
155
+ - 数据库结果仅在运行期间保存
156
+
157
+ ## 🐛 故障排除
158
+
159
+ ### Space 一直处于 "Starting" 状态
160
+
161
+ **原因**: 服务未能在规定时间内响应健康检查
162
+
163
+ **解决方案**:
164
+ 1. 检查 Dockerfile 是否正确暴露端口 7860
165
+ 2. 确保 `api_solver.py` 监听 0.0.0.0:7860
166
+ 3. 查看日志确认是否有错误
167
+
168
+ ### 浏览器初始化失败
169
+
170
+ **原因**: 系统依赖缺失或资源不足
171
+
172
+ **解决方案**:
173
+ 1. 检查 Dockerfile 中的系统依赖是否完整
174
+ 2. 升级到更高配置的硬件
175
+ 3. 减少线程数(`--thread 2`)
176
+
177
+ ### API 返回 503 错误
178
+
179
+ **原因**: 浏览器池尚未初始化完成
180
+
181
+ **解决方案**:
182
+ 1. 等待 30-60 秒后重试
183
+ 2. 使用 `/ready` 端点检查就绪状态
184
+ 3. 查看日志确认初始化进度
185
+
186
+ ## 📞 获取帮助
187
+
188
+ 如果遇到问题,请访问:
189
+
190
+ - 📢 **Telegram 频道**: [https://t.me/D3_vin](https://t.me/D3_vin)
191
+ - 💬 **Telegram 聊天**: [https://t.me/D3vin_chat](https://t.me/D3vin_chat)
192
+ - 📁 **GitHub Issues**: [https://github.com/D3-vin](https://github.com/D3-vin)
193
+
194
+ ## 📄 许可证
195
+
196
+ 本项目仅供教育用途。使用风险自负。
Dockerfile CHANGED
@@ -52,8 +52,8 @@ COPY . .
52
  # 创建 proxies.txt 文件(如果不存在)
53
  RUN touch proxies.txt
54
 
55
- # 暴露 API 端口
56
- EXPOSE 6080
57
 
58
- # 设置启动命令
59
- CMD ["python", "api_solver.py", "--host", "0.0.0.0", "--port", "6080"]
 
52
  # 创建 proxies.txt 文件(如果不存在)
53
  RUN touch proxies.txt
54
 
55
+ # 暴露 API 端口(Hugging Face Spaces 使用 7860)
56
+ EXPOSE 7860
57
 
58
+ # 设置启动命令(使用 HF Spaces 标准端口 7860)
59
+ CMD ["python", "api_solver.py", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,267 +1,99 @@
1
- ---
2
- title: G3 E
3
- emoji: 📉
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
-
11
- # Cloudflare - Turnstile Solver NEW
12
-
13
- ## 📢 Connect with Us
14
-
15
- - **📢 Channel**: [https://t.me/D3_vin](https://t.me/D3_vin) - Latest updates and releases
16
- - **💬 Chat**: [https://t.me/D3vin_chat](https://t.me/D3vin_chat) - Community support and discussions
17
- - **📁 GitHub**: [https://github.com/D3-vin](https://github.com/D3-vin) - Source code and development
18
-
19
- ![Python](https://img.shields.io/badge/Python-3.6+-blue)
20
- ![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
21
- ![License](https://img.shields.io/badge/License-Educational%20Use-green)
22
-
23
-
24
- ❤️ Support the Project
25
- If you find this collection valuable and appreciate the effort involved in obtaining and sharing these insights, please consider supporting the project. Your contribution helps keep this resource updated and allows for further exploration.
26
-
27
- You can show your support via:
28
-
29
- Cryptocurrency:
30
- - **EVM:** 0xeba21af63e707ce84b76a87d0ba82140048c057e (ETH,BNB,etc)
31
- - **TRON:** TEfECnyz5G1EkFrUqnbFcWLVdLvAgW9Raa
32
- - **TON:** UQCJ7KC2zxV_zKwLahaHf9jxy0vsWRcvQFie_FUBJW-9LcEW
33
- - **BTC:** bc1qdag98y5yahs6wf7rsfeh4cadsjfzmn5ngpjrcf
34
- - **SOL:** EwXXR4VqmWSNz1sjhZ8qcQ882i4URwAwhixSPEbDzyv6
35
- - **SUI:** 0x76da9b74c61508fbbd0b3e1989446e036b0622f252dd8d07c3fce759b239b47d
36
-
37
-
38
- 🙏 Thank you for your support!
39
-
40
- A Python-based Turnstile solver using the patchright and camoufox libraries, featuring multi-threaded execution, API integration, and support for different browsers. It solves CAPTCHAs quickly and efficiently, with customizable configurations and detailed logging.
41
-
42
- ## 🚀 Features
43
-
44
- - **Multi-threaded execution** - Solve multiple CAPTCHAs simultaneously
45
- - **Multiple browser support** - Chromium, Chrome, Edge, and Camoufox
46
- - **Proxy support** - Use proxies from proxies.txt file
47
- - **Random browser configurations** - Rotate User-Agent and Sec-CH-UA headers
48
- - **Detailed logging** - Comprehensive debug information
49
- - **REST API** - Easy integration with other applications
50
- - **Database storage** - SQLite database for result persistence
51
- - **Automatic cleanup** - Old results are automatically cleaned up
52
- - **Image blocking** - Optimized performance by blocking unnecessary images
53
-
54
- ## 🔧 Configuration
55
-
56
- ### Browser Configurations
57
-
58
- The solver supports various browser configurations with realistic User-Agent strings and Sec-CH-UA headers:
59
-
60
- - **Chrome** (versions 136-139)
61
- - **Edge** (versions 137-139)
62
- - **Avast** (versions 137-138)
63
- - **Brave** (versions 137-139)
64
-
65
- ### Proxy Format
66
-
67
- Add proxies to `proxies.txt` in the following formats:
68
-
69
- ```
70
- ip:port
71
- ip:port:username:password
72
- scheme://ip:port
73
- scheme://username:password@ip:port
74
- ```
75
-
76
- ## ❗ Disclaimers
77
-
78
- I am not responsible for anything that may happen, such as API Blocking, IP ban, etc.
79
- This was a quick project that was made for fun and personal use if you want to see further updates, star the repo & create an "issue" here
80
-
81
- ## ⚙️ Installation Instructions
82
-
83
- Ensure Python 3.8+ is installed on your system.
84
-
85
- ### 1. Create a Python virtual environment:
86
-
87
- ```bash
88
- python -m venv venv
89
- ```
90
-
91
- ### 2. Activate the virtual environment:
92
-
93
- **On Windows:**
94
- ```bash
95
- venv\Scripts\activate
96
- ```
97
-
98
- **On macOS/Linux:**
99
- ```bash
100
- source venv/bin/activate
101
- ```
102
-
103
- ### 3. Install required dependencies:
104
-
105
- ```bash
106
- pip install -r requirements.txt
107
- ```
108
-
109
- ### 4. Select the browser to install:
110
-
111
- You can choose between Chromium, Chrome, Edge or Camoufox:
112
-
113
- **To install Chromium:**
114
- ```bash
115
- python -m patchright install chromium
116
- ```
117
-
118
- **To install Chrome:**
119
- - **On macOS/Windows:** [Click here](https://www.google.com/chrome/)
120
- - **On Linux (Debian/Ubuntu-based):**
121
- ```bash
122
- apt update
123
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
124
- apt install -y ./google-chrome-stable_current_amd64.deb
125
- apt -f install -y # Fix dependencies if needed
126
- rm ./google-chrome-stable_current_amd64.deb
127
- ```
128
-
129
- **To install Edge:**
130
- ```bash
131
- python -m patchright install msedge
132
- ```
133
-
134
- **To install Camoufox:**
135
- ```bash
136
- python -m camoufox fetch
137
- ```
138
-
139
- ### 5. Start testing:
140
-
141
- Run the script (Check [🔧 Command line arguments](#-command-line-arguments) for better setup):
142
-
143
- ```bash
144
- python api_solver.py
145
- ```
146
-
147
- ## 🔧 Command line arguments
148
-
149
- | Parameter | Default | Type | Description |
150
- |-----------|---------|------|-------------|
151
- | `--no-headless` | False | boolean | Runs the browser with GUI (disable headless mode). By default, headless mode is enabled. |
152
- | `--useragent` | None | string | Specifies a custom User-Agent string for the browser. (No need to set if camoufox used) |
153
- | `--debug` | False | boolean | Enables or disables debug mode for additional logging and troubleshooting. |
154
- | `--browser_type` | chromium | string | Specify the browser type for the solver. Supported options: chromium, chrome, msedge, camoufox |
155
- | `--thread` | 4 | integer | Sets the number of browser threads to use in multi-threaded mode. |
156
- | `--host` | 0.0.0.0 | string | Specifies the IP address the API solver runs on. |
157
- | `--port` | 6080 | integer | Sets the port the API solver listens on. |
158
- | `--proxy` | False | boolean | Select a random proxy from proxies.txt for solving captchas |
159
- | `--random` | False | boolean | Use random User-Agent and Sec-CH-UA configuration from pool |
160
- | `--browser` | None | string | Specify browser name to use (e.g., chrome, firefox) |
161
- | `--version` | None | string | Specify browser version to use (e.g., 139, 141) |
162
-
163
- ## 📡 API Documentation
164
-
165
- ### Solve turnstile
166
-
167
- ```
168
- GET /turnstile?url=https://example.com&sitekey=0x4AAAAAAA
169
- ```
170
-
171
- **Request Parameters:**
172
-
173
- | Parameter | Type | Description | Required |
174
- |-----------|------|-------------|----------|
175
- | `url` | string | The target URL containing the CAPTCHA. (e.g., https://example.com) | Yes |
176
- | `sitekey` | string | The site key for the CAPTCHA to be solved. (e.g., 0x4AAAAAAA) | Yes |
177
- | `action` | string | Action to trigger during CAPTCHA solving, e.g., login | No |
178
- | `cdata` | string | Custom data that can be used for additional CAPTCHA parameters. | No |
179
-
180
- **Response:**
181
-
182
- If the request is successfully received, the server will respond with a task_id for the CAPTCHA solving task:
183
-
184
- ```json
185
- {
186
- "task_id": "d2cbb257-9c37-4f9c-9bc7-1eaee72d96a8"
187
- }
188
- ```
189
-
190
- ### Get Result
191
-
192
- ```
193
- GET /result?id=f0dbe75b-fa76-41ad-89aa-4d3a392040af
194
- ```
195
-
196
- **Request Parameters:**
197
-
198
- | Parameter | Type | Description | Required |
199
- |-----------|------|-------------|----------|
200
- | `id` | string | The unique task ID returned from the /turnstile request. | Yes |
201
-
202
- **Response:**
203
-
204
- If the CAPTCHA is solved successfully, the server will respond with the following information:
205
-
206
- ```json
207
- {
208
- "status": "ready",
209
- "value": "0.KBtT-r",
210
- "elapsed_time": 7.625
211
- }
212
- ```
213
-
214
- **Error Responses:**
215
-
216
- ```json
217
- {
218
- "status": "processing"
219
- }
220
- ```
221
-
222
- ```json
223
- {
224
- "status": "fail",
225
- "value": "CAPTCHA_FAIL",
226
- "elapsed_time": 30.0
227
- }
228
- ```
229
-
230
-
231
-
232
- ## 🐛 Troubleshooting
233
-
234
- ### Common Issues
235
-
236
- 1. **Browser not found**: Make sure you've installed the required browser using the installation instructions
237
- 2. **Permission denied**: Run with appropriate permissions or check file permissions
238
- 3. **Port already in use**: Change the port using `--port` argument
239
- 4. **Proxy connection failed**: Check proxy format and availability
240
-
241
- ### Debug Mode
242
-
243
- Enable debug mode for detailed logging:
244
-
245
- ```bash
246
- python api_solver.py --debug
247
- ```
248
-
249
- ## 📊 Performance
250
-
251
- - **Average solving time**: 5-15 seconds
252
- - **Success rate**: 95%+ (depending on site complexity)
253
- - **Memory usage**: ~50-100MB per browser thread
254
- - **CPU usage**: Moderate (depends on thread count)
255
-
256
- ## 🤝 Contributing
257
-
258
- 1. Fork the repository
259
- 2. Create a feature branch
260
- 3. Make your changes
261
- 4. Add tests if applicable
262
- 5. Submit a pull request
263
-
264
- ## 📄 License
265
-
266
- This project is for educational purposes only. Use at your own risk.
267
-
 
1
+ ---
2
+ title: Turnstile Solver API
3
+ emoji: 🔓
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ ---
10
+
11
+ # Cloudflare Turnstile Solver API
12
+
13
+ 这是一个基于 Python Cloudflare Turnstile 验证码求解器 API 服务。
14
+
15
+ ## 🚀 特性
16
+
17
+ - **多线程执行** - 同时解决多个验证码
18
+ - **多浏览器支持** - Chromium, Chrome, Edge 和 Camoufox
19
+ - **代理支持** - 使用 proxies.txt 文件中的代理
20
+ - **REST API** - 易于与其他应用程序集成
21
+ - **健康检查** - 提供 `/health` 和 `/ready` 端点
22
+
23
+ ## 📡 API 使用方法
24
+
25
+ ### 健康检查
26
+ ```
27
+ GET /health
28
+ ```
29
+ 返回服务健康状态
30
+
31
+ ### 就绪检查
32
+ ```
33
+ GET /ready
34
+ ```
35
+ 检查浏览器池是否已初始化完成
36
+
37
+ ### 求解 Turnstile
38
+ ```
39
+ GET /turnstile?url=https://example.com&sitekey=0x4AAAAAAA
40
+ ```
41
+
42
+ **请求参数:**
43
+
44
+ | 参数 | 类型 | 描述 | 必需 |
45
+ |------|------|------|------|
46
+ | `url` | string | 包含验证码的目标 URL | 是 |
47
+ | `sitekey` | string | 验证码的 site key | 是 |
48
+ | `action` | string | 验证码触发的动作 | 否 |
49
+ | `cdata` | string | 自定义数据 | |
50
+
51
+ **响应:**
52
+
53
+ ```json
54
+ {
55
+ "errorId": 0,
56
+ "taskId": "d2cbb257-9c37-4f9c-9bc7-1eaee72d96a8"
57
+ }
58
+ ```
59
+
60
+ ### 获取结果
61
+ ```
62
+ GET /result?id=f0dbe75b-fa76-41ad-89aa-4d3a392040af
63
+ ```
64
+
65
+ **响应 (成功):**
66
+
67
+ ```json
68
+ {
69
+ "errorId": 0,
70
+ "status": "ready",
71
+ "solution": {
72
+ "token": "0.KBtT-r..."
73
+ }
74
+ }
75
+ ```
76
+
77
+ **响应 (处理中):**
78
+
79
+ ```json
80
+ {
81
+ "status": "processing"
82
+ }
83
+ ```
84
+
85
+ ## ⚠️ 注意事项
86
+
87
+ - 服务启动后需要等待浏览器池初始化(约 30-60 秒)
88
+ - 在浏览器池就绪前,请求会返回 503 错误
89
+ - 可以通过 `/ready` 端点检查服务是否就绪
90
+
91
+ ## 📞 联系方式
92
+
93
+ - 📢 **频道**: [https://t.me/D3_vin](https://t.me/D3_vin)
94
+ - 💬 **聊天**: [https://t.me/D3vin_chat](https://t.me/D3vin_chat)
95
+ - 📁 **GitHub**: [https://github.com/D3-vin](https://github.com/D3-vin)
96
+
97
+ ## 📄 许可证
98
+
99
+ 本项目仅供教育用途。使用��险自负。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README_bak.md ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Cloudflare - Turnstile Solver NEW
2
+
3
+ ## 📢 Connect with Us
4
+
5
+ - **📢 Channel**: [https://t.me/D3_vin](https://t.me/D3_vin) - Latest updates and releases
6
+ - **💬 Chat**: [https://t.me/D3vin_chat](https://t.me/D3vin_chat) - Community support and discussions
7
+ - **📁 GitHub**: [https://github.com/D3-vin](https://github.com/D3-vin) - Source code and development
8
+
9
+ ![Python](https://img.shields.io/badge/Python-3.6+-blue)
10
+ ![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
11
+ ![License](https://img.shields.io/badge/License-Educational%20Use-green)
12
+
13
+
14
+ ❤️ Support the Project
15
+ If you find this collection valuable and appreciate the effort involved in obtaining and sharing these insights, please consider supporting the project. Your contribution helps keep this resource updated and allows for further exploration.
16
+
17
+ You can show your support via:
18
+
19
+ Cryptocurrency:
20
+ - **EVM:** 0xeba21af63e707ce84b76a87d0ba82140048c057e (ETH,BNB,etc)
21
+ - **TRON:** TEfECnyz5G1EkFrUqnbFcWLVdLvAgW9Raa
22
+ - **TON:** UQCJ7KC2zxV_zKwLahaHf9jxy0vsWRcvQFie_FUBJW-9LcEW
23
+ - **BTC:** bc1qdag98y5yahs6wf7rsfeh4cadsjfzmn5ngpjrcf
24
+ - **SOL:** EwXXR4VqmWSNz1sjhZ8qcQ882i4URwAwhixSPEbDzyv6
25
+ - **SUI:** 0x76da9b74c61508fbbd0b3e1989446e036b0622f252dd8d07c3fce759b239b47d
26
+
27
+
28
+ 🙏 Thank you for your support!
29
+
30
+ A Python-based Turnstile solver using the patchright and camoufox libraries, featuring multi-threaded execution, API integration, and support for different browsers. It solves CAPTCHAs quickly and efficiently, with customizable configurations and detailed logging.
31
+
32
+ ## 🚀 Features
33
+
34
+ - **Multi-threaded execution** - Solve multiple CAPTCHAs simultaneously
35
+ - **Multiple browser support** - Chromium, Chrome, Edge, and Camoufox
36
+ - **Proxy support** - Use proxies from proxies.txt file
37
+ - **Random browser configurations** - Rotate User-Agent and Sec-CH-UA headers
38
+ - **Detailed logging** - Comprehensive debug information
39
+ - **REST API** - Easy integration with other applications
40
+ - **Database storage** - SQLite database for result persistence
41
+ - **Automatic cleanup** - Old results are automatically cleaned up
42
+ - **Image blocking** - Optimized performance by blocking unnecessary images
43
+
44
+ ## 🔧 Configuration
45
+
46
+ ### Browser Configurations
47
+
48
+ The solver supports various browser configurations with realistic User-Agent strings and Sec-CH-UA headers:
49
+
50
+ - **Chrome** (versions 136-139)
51
+ - **Edge** (versions 137-139)
52
+ - **Avast** (versions 137-138)
53
+ - **Brave** (versions 137-139)
54
+
55
+ ### Proxy Format
56
+
57
+ Add proxies to `proxies.txt` in the following formats:
58
+
59
+ ```
60
+ ip:port
61
+ ip:port:username:password
62
+ scheme://ip:port
63
+ scheme://username:password@ip:port
64
+ ```
65
+
66
+ ## ❗ Disclaimers
67
+
68
+ I am not responsible for anything that may happen, such as API Blocking, IP ban, etc.
69
+ This was a quick project that was made for fun and personal use if you want to see further updates, star the repo & create an "issue" here
70
+
71
+ ## ⚙️ Installation Instructions
72
+
73
+ Ensure Python 3.8+ is installed on your system.
74
+
75
+ ### 1. Create a Python virtual environment:
76
+
77
+ ```bash
78
+ python -m venv venv
79
+ ```
80
+
81
+ ### 2. Activate the virtual environment:
82
+
83
+ **On Windows:**
84
+ ```bash
85
+ venv\Scripts\activate
86
+ ```
87
+
88
+ **On macOS/Linux:**
89
+ ```bash
90
+ source venv/bin/activate
91
+ ```
92
+
93
+ ### 3. Install required dependencies:
94
+
95
+ ```bash
96
+ pip install -r requirements.txt
97
+ ```
98
+
99
+ ### 4. Select the browser to install:
100
+
101
+ You can choose between Chromium, Chrome, Edge or Camoufox:
102
+
103
+ **To install Chromium:**
104
+ ```bash
105
+ python -m patchright install chromium
106
+ ```
107
+
108
+ **To install Chrome:**
109
+ - **On macOS/Windows:** [Click here](https://www.google.com/chrome/)
110
+ - **On Linux (Debian/Ubuntu-based):**
111
+ ```bash
112
+ apt update
113
+ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
114
+ apt install -y ./google-chrome-stable_current_amd64.deb
115
+ apt -f install -y # Fix dependencies if needed
116
+ rm ./google-chrome-stable_current_amd64.deb
117
+ ```
118
+
119
+ **To install Edge:**
120
+ ```bash
121
+ python -m patchright install msedge
122
+ ```
123
+
124
+ **To install Camoufox:**
125
+ ```bash
126
+ python -m camoufox fetch
127
+ ```
128
+
129
+ ### 5. Start testing:
130
+
131
+ Run the script (Check [🔧 Command line arguments](#-command-line-arguments) for better setup):
132
+
133
+ ```bash
134
+ python api_solver.py
135
+ ```
136
+
137
+ ## 🔧 Command line arguments
138
+
139
+ | Parameter | Default | Type | Description |
140
+ |-----------|---------|------|-------------|
141
+ | `--no-headless` | False | boolean | Runs the browser with GUI (disable headless mode). By default, headless mode is enabled. |
142
+ | `--useragent` | None | string | Specifies a custom User-Agent string for the browser. (No need to set if camoufox used) |
143
+ | `--debug` | False | boolean | Enables or disables debug mode for additional logging and troubleshooting. |
144
+ | `--browser_type` | chromium | string | Specify the browser type for the solver. Supported options: chromium, chrome, msedge, camoufox |
145
+ | `--thread` | 4 | integer | Sets the number of browser threads to use in multi-threaded mode. |
146
+ | `--host` | 0.0.0.0 | string | Specifies the IP address the API solver runs on. |
147
+ | `--port` | 6080 | integer | Sets the port the API solver listens on. |
148
+ | `--proxy` | False | boolean | Select a random proxy from proxies.txt for solving captchas |
149
+ | `--random` | False | boolean | Use random User-Agent and Sec-CH-UA configuration from pool |
150
+ | `--browser` | None | string | Specify browser name to use (e.g., chrome, firefox) |
151
+ | `--version` | None | string | Specify browser version to use (e.g., 139, 141) |
152
+
153
+ ## 📡 API Documentation
154
+
155
+ ### Solve turnstile
156
+
157
+ ```
158
+ GET /turnstile?url=https://example.com&sitekey=0x4AAAAAAA
159
+ ```
160
+
161
+ **Request Parameters:**
162
+
163
+ | Parameter | Type | Description | Required |
164
+ |-----------|------|-------------|----------|
165
+ | `url` | string | The target URL containing the CAPTCHA. (e.g., https://example.com) | Yes |
166
+ | `sitekey` | string | The site key for the CAPTCHA to be solved. (e.g., 0x4AAAAAAA) | Yes |
167
+ | `action` | string | Action to trigger during CAPTCHA solving, e.g., login | No |
168
+ | `cdata` | string | Custom data that can be used for additional CAPTCHA parameters. | No |
169
+
170
+ **Response:**
171
+
172
+ If the request is successfully received, the server will respond with a task_id for the CAPTCHA solving task:
173
+
174
+ ```json
175
+ {
176
+ "task_id": "d2cbb257-9c37-4f9c-9bc7-1eaee72d96a8"
177
+ }
178
+ ```
179
+
180
+ ### Get Result
181
+
182
+ ```
183
+ GET /result?id=f0dbe75b-fa76-41ad-89aa-4d3a392040af
184
+ ```
185
+
186
+ **Request Parameters:**
187
+
188
+ | Parameter | Type | Description | Required |
189
+ |-----------|------|-------------|----------|
190
+ | `id` | string | The unique task ID returned from the /turnstile request. | Yes |
191
+
192
+ **Response:**
193
+
194
+ If the CAPTCHA is solved successfully, the server will respond with the following information:
195
+
196
+ ```json
197
+ {
198
+ "status": "ready",
199
+ "value": "0.KBtT-r",
200
+ "elapsed_time": 7.625
201
+ }
202
+ ```
203
+
204
+ **Error Responses:**
205
+
206
+ ```json
207
+ {
208
+ "status": "processing"
209
+ }
210
+ ```
211
+
212
+ ```json
213
+ {
214
+ "status": "fail",
215
+ "value": "CAPTCHA_FAIL",
216
+ "elapsed_time": 30.0
217
+ }
218
+ ```
219
+
220
+
221
+
222
+ ## 🐛 Troubleshooting
223
+
224
+ ### Common Issues
225
+
226
+ 1. **Browser not found**: Make sure you've installed the required browser using the installation instructions
227
+ 2. **Permission denied**: Run with appropriate permissions or check file permissions
228
+ 3. **Port already in use**: Change the port using `--port` argument
229
+ 4. **Proxy connection failed**: Check proxy format and availability
230
+
231
+ ### Debug Mode
232
+
233
+ Enable debug mode for detailed logging:
234
+
235
+ ```bash
236
+ python api_solver.py --debug
237
+ ```
238
+
239
+ ## 📊 Performance
240
+
241
+ - **Average solving time**: 5-15 seconds
242
+ - **Success rate**: 95%+ (depending on site complexity)
243
+ - **Memory usage**: ~50-100MB per browser thread
244
+ - **CPU usage**: Moderate (depends on thread count)
245
+
246
+ ## 🤝 Contributing
247
+
248
+ 1. Fork the repository
249
+ 2. Create a feature branch
250
+ 3. Make your changes
251
+ 4. Add tests if applicable
252
+ 5. Submit a pull request
253
+
254
+ ## 📄 License
255
+
256
+ This project is for educational purposes only. Use at your own risk.
257
+
api_solver.py CHANGED
@@ -73,6 +73,8 @@ class TurnstileAPIServer:
73
  self.browser_name = browser_name
74
  self.browser_version = browser_version
75
  self.console = Console()
 
 
76
 
77
  # Initialize useragent and sec_ch_ua attributes
78
  self.useragent = useragent
@@ -138,22 +140,41 @@ class TurnstileAPIServer:
138
  self.app.route('/turnstile', methods=['GET'])(self.process_turnstile)
139
  self.app.route('/result', methods=['GET'])(self.get_result)
140
  self.app.route('/')(self.index)
 
 
141
 
142
 
143
  async def _startup(self) -> None:
144
- """Initialize the browser and page pool on startup."""
145
  self.display_welcome()
146
- logger.info("Starting browser initialization")
147
  try:
 
148
  await init_db()
149
- await self._initialize_browser()
 
 
 
150
 
151
- # Запускаем периодическую очистку старых результатов
152
  asyncio.create_task(self._periodic_cleanup())
153
 
 
 
154
  except Exception as e:
155
- logger.error(f"Failed to initialize browser: {str(e)}")
156
  raise
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  async def _initialize_browser(self) -> None:
159
  """Initialize the browser and create the page pool."""
@@ -767,6 +788,14 @@ class TurnstileAPIServer:
767
 
768
  async def process_turnstile(self):
769
  """Handle the /turnstile endpoint requests."""
 
 
 
 
 
 
 
 
770
  url = request.args.get('url')
771
  sitekey = request.args.get('sitekey')
772
  action = request.args.get('action')
@@ -921,8 +950,8 @@ def parse_args():
921
  parser.add_argument('--random', action='store_true', help='Use random User-Agent and Sec-CH-UA configuration from pool')
922
  parser.add_argument('--browser', type=str, help='Specify browser name to use (e.g., chrome, firefox)')
923
  parser.add_argument('--version', type=str, help='Specify browser version to use (e.g., 139, 141)')
924
- parser.add_argument('--host', type=str, default='0.0.0.0', help='Specify the IP address where the API solver runs. (Default: 127.0.0.1)')
925
- parser.add_argument('--port', type=str, default='5072', help='Set the port for the API solver to listen on. (Default: 5072)')
926
  return parser.parse_args()
927
 
928
 
 
73
  self.browser_name = browser_name
74
  self.browser_version = browser_version
75
  self.console = Console()
76
+ self.is_ready = False # 添加就绪状态标志
77
+ self.initialization_task = None # 初始化任务引用
78
 
79
  # Initialize useragent and sec_ch_ua attributes
80
  self.useragent = useragent
 
140
  self.app.route('/turnstile', methods=['GET'])(self.process_turnstile)
141
  self.app.route('/result', methods=['GET'])(self.get_result)
142
  self.app.route('/')(self.index)
143
+ self.app.route('/health', methods=['GET'])(self.health_check)
144
+ self.app.route('/ready', methods=['GET'])(self.readiness_check)
145
 
146
 
147
  async def _startup(self) -> None:
148
+ """Initialize the application on startup."""
149
  self.display_welcome()
150
+ logger.info("Starting application initialization")
151
  try:
152
+ # 初始化数据库(快速操作)
153
  await init_db()
154
+ logger.info("Database initialized successfully")
155
+
156
+ # 启动后台浏览器初始化任务(不阻塞启动)
157
+ self.initialization_task = asyncio.create_task(self._delayed_browser_init())
158
 
159
+ # 启动周期性清理任务
160
  asyncio.create_task(self._periodic_cleanup())
161
 
162
+ logger.info("Application startup completed, browser initialization in progress...")
163
+
164
  except Exception as e:
165
+ logger.error(f"Failed to initialize application: {str(e)}")
166
  raise
167
+
168
+ async def _delayed_browser_init(self) -> None:
169
+ """延迟初始化浏览器池(后台任务)"""
170
+ try:
171
+ logger.info("Starting browser initialization in background...")
172
+ await self._initialize_browser()
173
+ self.is_ready = True
174
+ logger.success("Browser pool initialized and ready to accept requests")
175
+ except Exception as e:
176
+ logger.error(f"Failed to initialize browser pool: {str(e)}")
177
+ self.is_ready = False
178
 
179
  async def _initialize_browser(self) -> None:
180
  """Initialize the browser and create the page pool."""
 
788
 
789
  async def process_turnstile(self):
790
  """Handle the /turnstile endpoint requests."""
791
+ # 检查服务是否就绪
792
+ if not self.is_ready:
793
+ return jsonify({
794
+ "errorId": 1,
795
+ "errorCode": "ERROR_SERVICE_NOT_READY",
796
+ "errorDescription": "Service is still initializing, please try again in a few moments"
797
+ }), 503
798
+
799
  url = request.args.get('url')
800
  sitekey = request.args.get('sitekey')
801
  action = request.args.get('action')
 
950
  parser.add_argument('--random', action='store_true', help='Use random User-Agent and Sec-CH-UA configuration from pool')
951
  parser.add_argument('--browser', type=str, help='Specify browser name to use (e.g., chrome, firefox)')
952
  parser.add_argument('--version', type=str, help='Specify browser version to use (e.g., 139, 141)')
953
+ parser.add_argument('--host', type=str, default='0.0.0.0', help='Specify the IP address where the API solver runs. (Default: 0.0.0.0)')
954
+ parser.add_argument('--port', type=str, default='7860', help='Set the port for the API solver to listen on. (Default: 7860 for HF Spaces)')
955
  return parser.parse_args()
956
 
957
 
docker-compose.yml CHANGED
@@ -5,7 +5,7 @@ services:
5
  build: .
6
  container_name: turnstile-solver
7
  ports:
8
- - "6080:6080"
9
  volumes:
10
  # 挂载 proxies.txt 文件(如果需要使用代理)
11
  - ./proxies.txt:/app/proxies.txt
@@ -16,7 +16,7 @@ services:
16
  command: >
17
  python api_solver.py
18
  --host 0.0.0.0
19
- --port 6080
20
  --thread 4
21
  --browser_type chromium
22
  restart: unless-stopped
@@ -24,7 +24,7 @@ services:
24
  # command: >
25
  # python api_solver.py
26
  # --host 0.0.0.0
27
- # --port 6080
28
  # --thread 4
29
  # --browser_type chromium
30
  # --proxy
 
5
  build: .
6
  container_name: turnstile-solver
7
  ports:
8
+ - "7860:7860"
9
  volumes:
10
  # 挂载 proxies.txt 文件(如果需要使用代理)
11
  - ./proxies.txt:/app/proxies.txt
 
16
  command: >
17
  python api_solver.py
18
  --host 0.0.0.0
19
+ --port 7860
20
  --thread 4
21
  --browser_type chromium
22
  restart: unless-stopped
 
24
  # command: >
25
  # python api_solver.py
26
  # --host 0.0.0.0
27
+ # --port 7860
28
  # --thread 4
29
  # --browser_type chromium
30
  # --proxy