try to improve captcha support
This commit is contained in:
@ -328,6 +328,27 @@ class MEXCRequestInterceptor:
|
||||
if request_info['postData']:
|
||||
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:
|
||||
logger.debug(f"Error processing request: {e}")
|
||||
|
||||
|
@ -13,6 +13,7 @@ import sys
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
import uuid
|
||||
|
||||
# Add the project root to path
|
||||
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")
|
||||
|
||||
# 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:
|
||||
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
|
||||
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):
|
||||
"""Interactive menu for testing different functions"""
|
||||
while True:
|
||||
@ -159,11 +183,7 @@ def interactive_menu(client: MEXCFuturesWebClient):
|
||||
test_position_opening(client, dry_run=True)
|
||||
|
||||
elif choice == "3":
|
||||
confirm = input("Are you sure you want to open a LIVE position? (type 'YES' to confirm): ")
|
||||
if confirm == "YES":
|
||||
test_position_opening(client, dry_run=False)
|
||||
else:
|
||||
print("Cancelled live trading")
|
||||
test_position_opening_live(client)
|
||||
|
||||
elif choice == "4":
|
||||
logger.info("DRY RUN: Position closing test")
|
||||
@ -226,7 +246,7 @@ def main():
|
||||
logger.error("No valid session available")
|
||||
return
|
||||
|
||||
client = MEXCFuturesWebClient(cookies)
|
||||
client = MEXCFuturesWebClient(session_cookies=cookies)
|
||||
|
||||
if not client.is_authenticated:
|
||||
logger.error("Failed to authenticate with MEXC")
|
||||
|
Reference in New Issue
Block a user