From d8de2b6d23cb9a79e41dc64ce0bc104a95bd5422 Mon Sep 17 00:00:00 2001 From: JosefVacha Date: Sat, 23 May 2026 16:44:57 +0200 Subject: [PATCH] fix: improve error handling for hCaptcha 500 errors (Issue #7) --- README.md | 19 +++++++++++++++++++ udio_wrapper/__init__.py | 18 ++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61a8722..18c10fc 100644 --- a/README.md +++ b/README.md @@ -164,11 +164,30 @@ This project is licensed under the MIT License. If you'd like to contribute to this project, feel free to fork the repository and send a pull request, or open an issue to discuss what you'd like to change. All contributions are welcome! +## Known Issues + +### hCaptcha Protection (Issue #7) + +As of April 2024, Udio has implemented hCaptcha protection on their API endpoints, particularly `/generate-proxy`. This causes automated requests to return `500 Server Error`. + +**Current Status:** +- Automated API requests are blocked by hCaptcha +- Browser-based workarounds (Selenium + undetected-chromedriver) have been attempted but are unreliable +- Even after manually solving captcha, subsequent requests may still fail + +**Possible Workarounds:** +1. **Browser Automation**: Use Selenium with undetected-chromedriver to handle captcha challenges (requires additional setup, may violate ToS) +2. **Wait for Official API**: Udio may release an official API with proper authentication +3. **Manual Session**: Maintain an active browser session and extract updated cookies/tokens + +**Note**: Contributing to the bypass of anti-bot systems may violate terms of service and could have legal/employment implications. + ## TODO ### Pending Tasks and Features - Improve error handling and response validation. +- Implement optional browser-based authentication to handle hCaptcha challenges. - Implement a user-friendly web interface for easier interaction with the API. ----- diff --git a/udio_wrapper/__init__.py b/udio_wrapper/__init__.py index d4ed8fe..39835c9 100644 --- a/udio_wrapper/__init__.py +++ b/udio_wrapper/__init__.py @@ -20,11 +20,25 @@ def __init__(self, auth_token): def make_request(self, url, method, data=None, headers=None): try: if method == 'POST': - response = requests.post(url, headers=headers, json=data) + response = requests.post(url, headers=headers, json=data, timeout=30) else: - response = requests.get(url, headers=headers) + response = requests.get(url, headers=headers, timeout=30) + + # Check for hCaptcha challenge (500 errors on generate-proxy endpoint) + if response.status_code == 500 and 'generate-proxy' in url: + print(f"ERROR: Received 500 Server Error from {url}") + print("CAUSE: Udio has implemented hCaptcha protection on this endpoint.") + print("SOLUTION: Automated requests are currently blocked. Consider:") + print(" 1. Using a browser-based approach (Selenium + undetected-chromedriver)") + print(" 2. Waiting for an official Udio API with proper authentication") + print(" 3. Manual interaction may be required per session") + return None + response.raise_for_status() return response + except requests.exceptions.Timeout: + print(f"Timeout error making {method} request to {url}") + return None except requests.exceptions.RequestException as e: print(f"Error making {method} request to {url}: {e}") return None