Debugging
Browse files
app.py
CHANGED
|
@@ -121,6 +121,27 @@ def create_service():
|
|
| 121 |
print(f"Service creation failed: {str(e)}")
|
| 122 |
return Service() # Fallback to simplest config
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
def setup_selenium():
|
| 125 |
try:
|
| 126 |
logger.info("Initializing Selenium Firefox driver...")
|
|
@@ -169,19 +190,20 @@ def setup_selenium():
|
|
| 169 |
# service=service
|
| 170 |
# # executable_path=os.path.join(os.getcwd(), 'geckodriver')
|
| 171 |
# )
|
|
|
|
| 172 |
try:
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
|
| 177 |
driver = webdriver.Firefox(
|
| 178 |
options=options,
|
| 179 |
service=service
|
| 180 |
)
|
| 181 |
-
|
| 182 |
|
| 183 |
except Exception as e:
|
| 184 |
-
|
| 185 |
|
| 186 |
# Last resort - try direct execution
|
| 187 |
try:
|
|
@@ -189,7 +211,7 @@ def setup_selenium():
|
|
| 189 |
run([geckodriver_path, "--version"], check=True)
|
| 190 |
run([options.binary_location, "--version"], check=True)
|
| 191 |
except Exception as sub_e:
|
| 192 |
-
|
| 193 |
logger.info("Selenium driver initialized successfully")
|
| 194 |
return driver
|
| 195 |
except Exception as e:
|
|
|
|
| 121 |
print(f"Service creation failed: {str(e)}")
|
| 122 |
return Service() # Fallback to simplest config
|
| 123 |
|
| 124 |
+
|
| 125 |
+
def verify_critical_path():
|
| 126 |
+
import os
|
| 127 |
+
from selenium.webdriver.firefox.options import Options
|
| 128 |
+
|
| 129 |
+
# Verify binaries exist
|
| 130 |
+
print(f"Geckodriver exists: {os.path.exists('/usr/local/bin/geckodriver')}")
|
| 131 |
+
print(f"Firefox exists: {os.path.exists('/usr/bin/firefox-esr')}")
|
| 132 |
+
|
| 133 |
+
# Check binary permissions
|
| 134 |
+
print(f"Geckodriver executable: {os.access('/usr/local/bin/geckodriver', os.X_OK)}")
|
| 135 |
+
print(f"Firefox executable: {os.access('/usr/bin/firefox-esr', os.X_OK)}")
|
| 136 |
+
|
| 137 |
+
# Test direct execution
|
| 138 |
+
import subprocess
|
| 139 |
+
try:
|
| 140 |
+
subprocess.run(["/usr/local/bin/geckodriver", "--version"], check=True)
|
| 141 |
+
subprocess.run(["/usr/bin/firefox-esr", "--version"], check=True)
|
| 142 |
+
except subprocess.CalledProcessError as e:
|
| 143 |
+
print(f"Binary test failed: {e}")
|
| 144 |
+
|
| 145 |
def setup_selenium():
|
| 146 |
try:
|
| 147 |
logger.info("Initializing Selenium Firefox driver...")
|
|
|
|
| 190 |
# service=service
|
| 191 |
# # executable_path=os.path.join(os.getcwd(), 'geckodriver')
|
| 192 |
# )
|
| 193 |
+
verify_critical_path()
|
| 194 |
try:
|
| 195 |
+
logger.info("Attempting Firefox initialization with:")
|
| 196 |
+
logger.info(f"Service: {service.__dict__}")
|
| 197 |
+
logger.info(f"Options: {options.__dict__}")
|
| 198 |
|
| 199 |
driver = webdriver.Firefox(
|
| 200 |
options=options,
|
| 201 |
service=service
|
| 202 |
)
|
| 203 |
+
logger.info("Successfully initialized driver!")
|
| 204 |
|
| 205 |
except Exception as e:
|
| 206 |
+
logger.info(f"Initialization failed completely: {str(e)}")
|
| 207 |
|
| 208 |
# Last resort - try direct execution
|
| 209 |
try:
|
|
|
|
| 211 |
run([geckodriver_path, "--version"], check=True)
|
| 212 |
run([options.binary_location, "--version"], check=True)
|
| 213 |
except Exception as sub_e:
|
| 214 |
+
logger.info(f"Subprocess check failed: {str(sub_e)}")
|
| 215 |
logger.info("Selenium driver initialized successfully")
|
| 216 |
return driver
|
| 217 |
except Exception as e:
|