try to improve captcha support
This commit is contained in:
@ -327,6 +327,27 @@ class MEXCRequestInterceptor:
|
|||||||
print(f"\n🚀 CAPTURED REQUEST: {request_info['method']} {url}")
|
print(f"\n🚀 CAPTURED REQUEST: {request_info['method']} {url}")
|
||||||
if request_info['postData']:
|
if request_info['postData']:
|
||||||
print(f" 📄 POST Data: {request_info['postData'][:100]}...")
|
print(f" 📄 POST Data: {request_info['postData'][:100]}...")
|
||||||
|
|
||||||
|
# Enhanced captcha detection and detailed logging
|
||||||
|
if 'captcha' in url.lower() or 'robot' in url.lower():
|
||||||
|
logger.info(f"CAPTCHA REQUEST DETECTED: {request_data.get('request', {}).get('method', 'UNKNOWN')} {url}")
|
||||||
|
logger.info(f" Headers: {request_data.get('request', {}).get('headers', {})}")
|
||||||
|
if request_data.get('request', {}).get('postData', ''):
|
||||||
|
logger.info(f" Data: {request_data.get('request', {}).get('postData', '')}")
|
||||||
|
# Attempt to capture related JavaScript or DOM elements (if possible)
|
||||||
|
if self.driver is not None:
|
||||||
|
try:
|
||||||
|
js_snippet = self.driver.execute_script("return document.querySelector('script[src*=\"captcha\"]') ? document.querySelector('script[src*=\"captcha\"]').outerHTML : 'No captcha script found';")
|
||||||
|
logger.info(f" Related JS Snippet: {js_snippet}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f" Could not capture JS snippet: {e}")
|
||||||
|
try:
|
||||||
|
dom_element = self.driver.execute_script("return document.querySelector('div[id*=\"captcha\"]') ? document.querySelector('div[id*=\"captcha\"]').outerHTML : 'No captcha element found';")
|
||||||
|
logger.info(f" Related DOM Element: {dom_element}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f" Could not capture DOM element: {e}")
|
||||||
|
else:
|
||||||
|
logger.warning(" Driver not initialized, cannot capture JS or DOM elements")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Error processing request: {e}")
|
logger.debug(f"Error processing request: {e}")
|
||||||
|
@ -13,6 +13,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import uuid
|
||||||
|
|
||||||
# Add the project root to path
|
# Add the project root to path
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
@ -81,7 +82,16 @@ def test_basic_connection():
|
|||||||
logger.warning("Extracted cookies may be incomplete")
|
logger.warning("Extracted cookies may be incomplete")
|
||||||
|
|
||||||
# Initialize the web client
|
# Initialize the web client
|
||||||
client = MEXCFuturesWebClient(cookies)
|
client = MEXCFuturesWebClient(session_cookies=cookies)
|
||||||
|
|
||||||
|
# Update headers to include additional parameters from captured requests
|
||||||
|
client.session.headers.update({
|
||||||
|
'trochilus-trace-id': f"{uuid.uuid4()}-{int(time.time() * 1000) % 10000:04d}",
|
||||||
|
'trochilus-uid': cookies.get('u_id', ''),
|
||||||
|
'Referer': 'https://www.mexc.com/en-GB/futures/ETH_USDT?type=linear_swap',
|
||||||
|
'Language': 'English',
|
||||||
|
'X-Language': 'en-GB'
|
||||||
|
})
|
||||||
|
|
||||||
if not client.is_authenticated:
|
if not client.is_authenticated:
|
||||||
logger.error("Failed to authenticate with extracted cookies")
|
logger.error("Failed to authenticate with extracted cookies")
|
||||||
@ -136,6 +146,20 @@ def test_position_opening(client: MEXCFuturesWebClient, dry_run: bool = True):
|
|||||||
# Test just the captcha verification part
|
# Test just the captcha verification part
|
||||||
return client.verify_captcha(symbol, 'openlong', f'{leverage}X')
|
return client.verify_captcha(symbol, 'openlong', f'{leverage}X')
|
||||||
|
|
||||||
|
def test_position_opening_live(client):
|
||||||
|
symbol = "ETH_USDT"
|
||||||
|
volume = 1 # Small volume for testing
|
||||||
|
leverage = 200
|
||||||
|
|
||||||
|
logger.info(f"LIVE TRADING: Opening actual position!")
|
||||||
|
logger.info(f"Attempting to open long position: {symbol}, Volume: {volume}, Leverage: {leverage}x")
|
||||||
|
|
||||||
|
result = client.open_long_position(symbol, volume, leverage)
|
||||||
|
if result.get('success'):
|
||||||
|
logger.info(f"Successfully opened position: {result}")
|
||||||
|
else:
|
||||||
|
logger.error(f"Failed to open position: {result.get('error', 'Unknown error')}")
|
||||||
|
|
||||||
def interactive_menu(client: MEXCFuturesWebClient):
|
def interactive_menu(client: MEXCFuturesWebClient):
|
||||||
"""Interactive menu for testing different functions"""
|
"""Interactive menu for testing different functions"""
|
||||||
while True:
|
while True:
|
||||||
@ -159,12 +183,8 @@ def interactive_menu(client: MEXCFuturesWebClient):
|
|||||||
test_position_opening(client, dry_run=True)
|
test_position_opening(client, dry_run=True)
|
||||||
|
|
||||||
elif choice == "3":
|
elif choice == "3":
|
||||||
confirm = input("Are you sure you want to open a LIVE position? (type 'YES' to confirm): ")
|
test_position_opening_live(client)
|
||||||
if confirm == "YES":
|
|
||||||
test_position_opening(client, dry_run=False)
|
|
||||||
else:
|
|
||||||
print("Cancelled live trading")
|
|
||||||
|
|
||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
logger.info("DRY RUN: Position closing test")
|
logger.info("DRY RUN: Position closing test")
|
||||||
success = client.verify_captcha('ETH_USDT', 'closelong', '200X')
|
success = client.verify_captcha('ETH_USDT', 'closelong', '200X')
|
||||||
@ -226,7 +246,7 @@ def main():
|
|||||||
logger.error("No valid session available")
|
logger.error("No valid session available")
|
||||||
return
|
return
|
||||||
|
|
||||||
client = MEXCFuturesWebClient(cookies)
|
client = MEXCFuturesWebClient(session_cookies=cookies)
|
||||||
|
|
||||||
if not client.is_authenticated:
|
if not client.is_authenticated:
|
||||||
logger.error("Failed to authenticate with MEXC")
|
logger.error("Failed to authenticate with MEXC")
|
||||||
|
Reference in New Issue
Block a user