diff --git a/README.md b/README.md index f6118a7..5d981f7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ already included within the image. We provide a `docker-compose.yml` configuration file. Clone this repository and execute `docker compose up -d` to start -the container. Http endpoint will be available after little delay (5-15 sec), because container install chrome of required version on start. +the container. ### From github as pip package > **Warning** diff --git a/rootfs/opt/flare_bypasser/bin/FlareBypasserRun.sh b/rootfs/opt/flare_bypasser/bin/FlareBypasserRun.sh index 874734b..f52b0a1 100755 --- a/rootfs/opt/flare_bypasser/bin/FlareBypasserRun.sh +++ b/rootfs/opt/flare_bypasser/bin/FlareBypasserRun.sh @@ -123,7 +123,9 @@ if [ "$CHROME_DISABLE_GPU" = true ] ; then ADD_PARAMS="$ADD_PARAMS --disable-gpu" fi -echo "Run server, extensions: $EXTENSION_MODULES, chrome: $(/usr/bin/chrome --version)" +echo "Run server $(pip show flare-bypasser | grep Version | awk '{print $2}' +), chrome: $(/usr/bin/chrome --version +), extensions: $EXTENSION_MODULES" flare_bypass_server -b 0.0.0.0:8080 $EXTENSION_MODULES_PARAM $ADD_PARAMS 2>&1 | \ tee "$WORKSPACE_ROOT/log/flare_bypass_server.log" diff --git a/setup.py b/setup.py index acbc72d..e1ee4da 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='flare-bypasser', python_requires='>= 3.9', - version='0.1.24', + version='0.1.25', packages=["flare_bypasser"], package_dir={ "": ".", diff --git a/src/flare_bypasser/browser_wrapper.py b/src/flare_bypasser/browser_wrapper.py index 421d7ad..ff4ffbd 100644 --- a/src/flare_bypasser/browser_wrapper.py +++ b/src/flare_bypasser/browser_wrapper.py @@ -1,4 +1,5 @@ import os +import sys import typing import asyncio import uuid @@ -55,11 +56,12 @@ def __init__(self, nodriver_driver: nodriver.Browser): @staticmethod def start_xvfb_display(): - global XVFB_DISPLAY - if XVFB_DISPLAY is None: - from xvfbwrapper import Xvfb - XVFB_DISPLAY = Xvfb() - XVFB_DISPLAY.start() + if sys.platform != 'win32': + global XVFB_DISPLAY + if XVFB_DISPLAY is None: + from xvfbwrapper import Xvfb + XVFB_DISPLAY = Xvfb() + XVFB_DISPLAY.start() @staticmethod async def create(proxy = None, disable_gpu = False): @@ -67,11 +69,14 @@ async def create(proxy = None, disable_gpu = False): browser_args = [] if proxy: browser_args.append("--proxy-server=" + proxy) - if disable_gpu : + if disable_gpu: browser_args += [ "--disable-gpu", "--disable-software-rasterizer" ] + if sys.platform == 'win32': + browser_args += ["--headless"] + nodriver_driver = await nodriver.start( sandbox=False, browser_args=browser_args diff --git a/src/flare_bypasser/flare_bypass_server.py b/src/flare_bypasser/flare_bypass_server.py index 8b6866c..30bc048 100644 --- a/src/flare_bypasser/flare_bypass_server.py +++ b/src/flare_bypasser/flare_bypass_server.py @@ -40,6 +40,7 @@ 'disable_gpu': False } + class HandleCommandResponseSolution(pydantic.BaseModel): status: str url: str @@ -390,7 +391,7 @@ def server_run(): end_port=args.proxy_listen_end_port, command=args.proxy_command) - if args.disable_gpu : + if args.disable_gpu: solver_args['disable_gpu'] = True if USE_GUNICORN: diff --git a/src/flare_bypasser/flare_bypasser.py b/src/flare_bypasser/flare_bypasser.py index d333dcb..7ce48d3 100644 --- a/src/flare_bypasser/flare_bypasser.py +++ b/src/flare_bypasser/flare_bypasser.py @@ -230,10 +230,10 @@ async def solve(self, req: Request) -> Response: return res async def _resolve_challenge(self, req: Request) -> Response: - start_time = datetime.datetime.now() + start_time: datetime.datetime = datetime.datetime.now() step = 'start' try: - use_proxy = (req.proxy if req.proxy else self._proxy) + use_proxy: str = (req.proxy if req.proxy else self._proxy) proxy_holder = None step = 'proxy init' @@ -245,10 +245,12 @@ async def _resolve_challenge(self, req: Request) -> Response: else: proxy_holder = contextlib.nullcontext() - step = 'solving' with proxy_holder: try: - self._driver = await BrowserWrapper.create(use_proxy, disable_gpu = self._disable_gpu) + step = 'browser init' + self._driver: BrowserWrapper = await BrowserWrapper.create( + use_proxy, disable_gpu = self._disable_gpu + ) logging.info( 'New instance of webdriver has been created to perform the request (proxy=' + str(use_proxy) + '), timeout=' + str(req.max_timeout)) @@ -260,11 +262,19 @@ async def _resolve_challenge(self, req: Request) -> Response: self._driver = None logging.debug('A used instance of webdriver has been destroyed') except Solver.Exception as e: - error_message = "Error solving the challenge. On step '" + str(e.step) + "': " + str(e).replace('\n', '\\n') + error_message = ( + "Error solving the challenge. On platform " + str(sys.platform) + + " at step '" + str(e.step) + "': " + + str(e).replace('\n', '\\n') + ) logging.error(error_message) raise Solver.Exception(error_message, step=e.step) except Exception as e: - error_message = "Error solving the challenge. On step '" + step + "': " + str(e).replace('\n', '\\n') + error_message = ( + "Error solving the challenge. On platform " + str(sys.platform) + + " at step '" + step + "': " + + str(e).replace('\n', '\\n') + ) logging.error(error_message) raise Solver.Exception(error_message) diff --git a/src/tests/unit_tests/proxy_controller_test.py b/src/tests/unit_tests/proxy_controller_test.py index da73489..10a8fb0 100644 --- a/src/tests/unit_tests/proxy_controller_test.py +++ b/src/tests/unit_tests/proxy_controller_test.py @@ -1,5 +1,6 @@ from flare_bypasser import ProxyController + def test_two_different_proxies_rent(): proxy_controller = ProxyController(command = 'echo "Listening on {{LOCAL_PORT}}"') @@ -10,6 +11,7 @@ def test_two_different_proxies_rent(): assert proxy_controller.opened_proxies_count() == 0 + def test_two_equal_proxies_rent(): proxy_controller = ProxyController(command = 'echo "Listening on {{LOCAL_PORT}}"') diff --git a/utils/linux_chrome_installer.py b/utils/linux_chrome_installer.py index 679f7a5..577c030 100644 --- a/utils/linux_chrome_installer.py +++ b/utils/linux_chrome_installer.py @@ -1,4 +1,5 @@ import os +import sys import shutil import logging import json @@ -10,6 +11,7 @@ def fetch_package(download_url): return urlretrieve(download_url)[0] + def unzip_package( fp, extract_root='/', unzip_path='/tmp/unzip_chrome', extract_sub_directory='' @@ -89,6 +91,8 @@ def download_and_install(version_prefix = None, install_root = None): try: res = download_and_install( version_prefix = args.version_prefix, - install_root = args.install_root) - except Exception as e : + install_root = args.install_root + ) + except Exception as e: + logging.error("Can't install chrome: " + str(e)) sys.exit(1)