Compare commits

...

10 Commits

Author SHA1 Message Date
Andrei 774361f3fd
Update README.md 2022-11-05 18:28:07 +03:00
Andrei 3528e5c194
Update README.md 2022-11-05 18:12:53 +03:00
Andrei 27647dab9d
Update README.md 2022-11-05 18:07:05 +03:00
Andrei e5314e843b Merge branch 'master' of github.com:AndreiDrang/python3-anticaptcha 2022-11-05 18:06:17 +03:00
Andrei 23bfb9c49d Create AntiCaptcha.png 2022-11-05 18:06:06 +03:00
Andrei 7ed51fbb69
Update README.md 2022-11-05 18:00:24 +03:00
Andrei 7e5b70b25f Update get_answer.py 2022-11-05 17:47:19 +03:00
Andrei f1eae92df3 Update get_answer.py 2022-11-05 17:45:56 +03:00
Andrei 2585b97bdb Update config.py 2022-11-05 17:45:53 +03:00
Andrei 286f2ea64a Update __init__.py 2022-11-05 17:45:50 +03:00
5 changed files with 38 additions and 23 deletions

View File

@ -1,28 +1,27 @@
# python3-anticaptcha
![AntiCaptcha](files/AntiCaptcha.png)
[![PyPI version](https://badge.fury.io/py/python3-anticaptcha.svg)](https://badge.fury.io/py/python3-anticaptcha)
[![Python versions](https://img.shields.io/pypi/pyversions/python3-anticaptcha.svg?logo=python&logoColor=FBE072)](https://badge.fury.io/py/python3-anticaptcha)
[![Build Status](https://semaphoreci.com/api/v1/andreidrang/python3-anticaptcha/branches/master/shields_badge.svg)](https://semaphoreci.com/andreidrang/python3-anticaptcha)
[![Build Status](https://travis-ci.org/AndreiDrang/python3-anticaptcha.svg?branch=master)](https://travis-ci.org/AndreiDrang/python3-anticaptcha)
[![Downloads](https://pepy.tech/badge/python3-anticaptcha/month)](https://pepy.tech/project/python3-anticaptcha)
[![Code Climate](https://codeclimate.com/github/AndreiDrang/python3-anticaptcha/badges/gpa.svg)](https://codeclimate.com/github/AndreiDrang/python3-anticaptcha)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2daabf7ff7974f01b9348fe64483c7af)](https://app.codacy.com/app/drang.andray/python3-anticaptcha?utm_source=github.com&utm_medium=referral&utm_content=AndreiDrang/python3-anticaptcha&utm_campaign=Badge_Grade_Settings)
Python 3.6+ library for [Anti-Captcha](https://anti-captcha.com/mainpage) service.
[Application in AppCenter](https://anti-captcha.com/clients/tools/appcenter/app/867).
Python3 library for [Anti-Captcha](https://anti-captcha.com/mainpage) service.
Tested on UNIX based OS.
The library is intended for software developers and is used to work with the AntiCaptcha service API.
The library is intended for software developers and is used to work with the [Anti-Captcha](https://anti-captcha.com/mainpage) service API.
***
По всем вопросам можете писать в [Telegram](https://t.me/pythoncaptcha) чат.
Application in [AppCenter](https://anti-captcha.com/clients/tools/appcenter/app/867).
Либо на email - python-captcha@pm.me
If you have any questions, please send a message to the [Telegram](https://t.me/pythoncaptcha) chat room.
With any questions, please contact us in [Telegram](https://t.me/pythoncaptcha).
Or by email - python-captcha@pm.me
Or email python-captcha@pm.me
***
## How to install? Как установить?
@ -65,6 +64,7 @@ custom_result = CustomResultHandler.CustomResultHandler(
user_answer = custom_result.task_handler(task_id=TASK_ID)
print(user_answer)
```
##### 1. [Image to text captcha.](./anticaptcha_examples/anticaptcah_image_to_text_example.py)

BIN
files/AntiCaptcha.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 KiB

View File

@ -1,3 +0,0 @@
from .config import app_key, get_result_url, create_task_url
from .errors import ReadError, IdGetError, ParamError
from .get_answer import get_sync_result, get_async_result

View File

@ -1,4 +1,5 @@
import urllib3
from typing import Generator
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@ -8,3 +9,18 @@ create_task_url = "https://api.anti-captcha.com/createTask"
get_result_url = "https://api.anti-captcha.com/getTaskResult"
# ключ приложения
app_key = "867"
# Connection retry generator
def attempts_generator(amount: int = 5) -> Generator:
"""
Function generates a generator of length equal to `amount`
Args:
amount: number of attempts generated
Returns:
Attempt number
"""
for i in range(1, amount):
yield i

View File

@ -5,18 +5,19 @@ import aiohttp
import requests
from requests.adapters import HTTPAdapter
from python3_anticaptcha import get_result_url
from python3_anticaptcha.config import attempts_generator, get_result_url
def get_sync_result(result_payload: dict, sleep_time: int, **kwargs) -> dict:
# создаём сессию
# create a session
session = requests.Session()
# выставляем кол-во попыток подключения к серверу при ошибке
# set the number of attempts to connect to the server in case of error
session.mount("http://", HTTPAdapter(max_retries=5))
session.mount("https://", HTTPAdapter(max_retries=5))
session.verify = False
while True:
attempts = attempts_generator()
for attempt in attempts:
captcha_response = session.post(get_result_url, json=result_payload, **kwargs).json()
if captcha_response["errorId"] == 0:
@ -33,17 +34,18 @@ def get_sync_result(result_payload: dict, sleep_time: int, **kwargs) -> dict:
async def get_async_result(result_payload: dict, sleep_time: int) -> dict:
# Отправляем запрос на статус решения капчи.
attempts = attempts_generator()
# Send request for status of captcha solution.
async with aiohttp.ClientSession() as session:
while True:
for attempt in attempts:
async with session.post(get_result_url, json=result_payload) as resp:
json_result = await resp.json()
# Если нет ошибки - проверяем статус капчи
# if there is no error, check CAPTCHA status
if json_result["errorId"] == 0:
# Если еще не решена, ожидаем
# If not yet resolved, wait
if json_result["status"] == "processing":
await asyncio.sleep(sleep_time)
# Иначе возвращаем ответ
# otherwise return response
else:
json_result.update({"taskId": result_payload["taskId"]})
return json_result