Update app.py
Browse files
app.py
CHANGED
|
@@ -523,15 +523,12 @@ class MultilingualTranslator:
|
|
| 523 |
def notify_wordpress_completion_and_charge(request_id: str, character_count: int,
|
| 524 |
translation_length: int, source_lang: str,
|
| 525 |
target_lang: str):
|
| 526 |
-
"""Enhanced WordPress notification with proper
|
| 527 |
try:
|
| 528 |
-
|
| 529 |
-
|
| 530 |
|
| 531 |
-
|
| 532 |
-
wordpress_urls = [
|
| 533 |
-
wordpress_base_url
|
| 534 |
-
]
|
| 535 |
|
| 536 |
payload = {
|
| 537 |
'request_id': request_id,
|
|
@@ -545,44 +542,37 @@ def notify_wordpress_completion_and_charge(request_id: str, character_count: int
|
|
| 545 |
|
| 546 |
headers = {
|
| 547 |
'Content-Type': 'application/json',
|
| 548 |
-
'Accept': 'application/json',
|
| 549 |
'User-Agent': 'MLT-Server/1.0'
|
| 550 |
}
|
| 551 |
|
| 552 |
-
|
| 553 |
-
notification_url = base_url.rstrip('/') + '/wp-json/mlt/v1/notification'
|
| 554 |
-
|
| 555 |
-
try:
|
| 556 |
-
print(f"Attempting WordPress notification to: {notification_url}")
|
| 557 |
-
|
| 558 |
-
response = requests.post(
|
| 559 |
-
notification_url,
|
| 560 |
-
json=payload,
|
| 561 |
-
headers=headers,
|
| 562 |
-
timeout=15,
|
| 563 |
-
verify=False
|
| 564 |
-
)
|
| 565 |
-
|
| 566 |
-
print(f"WordPress response status: {response.status_code}")
|
| 567 |
-
print(f"WordPress response body: {response.text[:200]}")
|
| 568 |
-
|
| 569 |
-
if response.status_code in [200, 201]:
|
| 570 |
-
if request_id in translator.translation_requests:
|
| 571 |
-
translator.translation_requests[request_id]['auto_charged'] = True
|
| 572 |
-
print(f"WordPress notification successful for request {request_id}")
|
| 573 |
-
return True
|
| 574 |
-
else:
|
| 575 |
-
print(f"WordPress notification failed: {response.status_code}")
|
| 576 |
-
|
| 577 |
-
except requests.exceptions.RequestException as e:
|
| 578 |
-
print(f"WordPress notification error: {str(e)}")
|
| 579 |
-
continue
|
| 580 |
|
| 581 |
-
|
| 582 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
|
| 584 |
except Exception as e:
|
| 585 |
-
print(f"WordPress notification error: {str(e)}")
|
| 586 |
return False
|
| 587 |
|
| 588 |
def process_heavy_translation_background(text: str, source_lang: str, target_lang: str,
|
|
|
|
| 523 |
def notify_wordpress_completion_and_charge(request_id: str, character_count: int,
|
| 524 |
translation_length: int, source_lang: str,
|
| 525 |
target_lang: str):
|
| 526 |
+
"""Enhanced WordPress notification with proper SSL handling"""
|
| 527 |
try:
|
| 528 |
+
import urllib3
|
| 529 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 530 |
|
| 531 |
+
wordpress_base_url = os.getenv("WORDPRESS_NOTIFICATION_URL", "https://yourdomain.com")
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
payload = {
|
| 534 |
'request_id': request_id,
|
|
|
|
| 542 |
|
| 543 |
headers = {
|
| 544 |
'Content-Type': 'application/json',
|
|
|
|
| 545 |
'User-Agent': 'MLT-Server/1.0'
|
| 546 |
}
|
| 547 |
|
| 548 |
+
notification_url = wordpress_base_url.rstrip('/') + '/wp-json/mlt/v1/notification'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
+
try:
|
| 551 |
+
print(f"Attempting WordPress notification to: {notification_url}")
|
| 552 |
+
|
| 553 |
+
response = requests.post(
|
| 554 |
+
notification_url,
|
| 555 |
+
json=payload,
|
| 556 |
+
headers=headers,
|
| 557 |
+
timeout=30,
|
| 558 |
+
verify=False # Disable SSL verification for compatibility
|
| 559 |
+
)
|
| 560 |
+
|
| 561 |
+
print(f"WordPress response status: {response.status_code}")
|
| 562 |
+
|
| 563 |
+
if response.status_code in [200, 201]:
|
| 564 |
+
print(f"WordPress notification successful for request {request_id}")
|
| 565 |
+
return True
|
| 566 |
+
else:
|
| 567 |
+
print(f"WordPress notification failed: {response.status_code}")
|
| 568 |
+
return False
|
| 569 |
+
|
| 570 |
+
except Exception as e:
|
| 571 |
+
print(f"WordPress notification error: {str(e)}")
|
| 572 |
+
return False
|
| 573 |
|
| 574 |
except Exception as e:
|
| 575 |
+
print(f"WordPress notification setup error: {str(e)}")
|
| 576 |
return False
|
| 577 |
|
| 578 |
def process_heavy_translation_background(text: str, source_lang: str, target_lang: str,
|