danicor commited on
Commit
4be5205
Β·
verified Β·
1 Parent(s): 266df91

Update app3.py

Browse files
Files changed (1) hide show
  1. app3.py +38 -4
app3.py CHANGED
@@ -338,21 +338,55 @@ class TranslationOrchestrator:
338
  self.notify_wordpress(notification_url, failure_data)
339
 
340
  def notify_wordpress(self, notification_url: str, data: Dict):
 
341
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  response = requests.post(
343
  notification_url,
344
  json=data,
 
345
  timeout=30,
346
- verify=False
347
  )
348
 
 
 
349
  if response.status_code == 200:
350
- print(f"πŸ“€ WordPress notified for {data['request_id']}")
 
351
  else:
352
- print(f"⚠ WordPress notification failed: HTTP {response.status_code}")
 
 
353
 
 
 
 
 
 
 
354
  except Exception as e:
355
- print(f"⚠ WordPress notification error: {str(e)}")
 
356
 
357
  # Initialize FastAPI app
358
  app = FastAPI(
 
338
  self.notify_wordpress(notification_url, failure_data)
339
 
340
  def notify_wordpress(self, notification_url: str, data: Dict):
341
+ """Send notification to WordPress with improved error handling"""
342
  try:
343
+ # Log the notification attempt
344
+ print(f"πŸ“€ Attempting to notify WordPress at: {notification_url}")
345
+
346
+ # Ensure HTTPS and proper URL format
347
+ if notification_url.startswith('http://localhost'):
348
+ # Replace localhost with the actual WordPress URL from environment
349
+ wordpress_url = os.getenv('WORDPRESS_BASE_URL', 'https://your-actual-site.com')
350
+ notification_url = notification_url.replace('http://localhost', wordpress_url)
351
+
352
+ # Ensure HTTPS
353
+ notification_url = notification_url.replace('http://', 'https://')
354
+
355
+ headers = {
356
+ 'Content-Type': 'application/json',
357
+ 'User-Agent': 'MLT-Orchestrator/1.0'
358
+ }
359
+
360
+ print(f"πŸ”— Final notification URL: {notification_url}")
361
+ print(f"πŸ“¦ Payload keys: {list(data.keys())}")
362
+
363
  response = requests.post(
364
  notification_url,
365
  json=data,
366
+ headers=headers,
367
  timeout=30,
368
+ verify=True # Keep SSL verification enabled
369
  )
370
 
371
+ print(f"πŸ“‘ WordPress notification response: {response.status_code}")
372
+
373
  if response.status_code == 200:
374
+ print(f"βœ… WordPress notified successfully for {data['request_id']}")
375
+ return True
376
  else:
377
+ print(f"❌ WordPress notification failed: HTTP {response.status_code}")
378
+ print(f"πŸ“„ Response: {response.text}")
379
+ return False
380
 
381
+ except requests.exceptions.Timeout:
382
+ print(f"⏰ WordPress notification timeout for {data['request_id']}")
383
+ return False
384
+ except requests.exceptions.ConnectionError as e:
385
+ print(f"πŸ”Œ WordPress connection error for {data['request_id']}: {str(e)}")
386
+ return False
387
  except Exception as e:
388
+ print(f"πŸ’₯ Notification error for {data['request_id']}: {str(e)}")
389
+ return False
390
 
391
  # Initialize FastAPI app
392
  app = FastAPI(