Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I try to call an external webService for translation

khaliDA BIKAM3 days ago

Hello everyOne

i try to do some conversion from french to english using this API external, but i have some troubles

this is the code i use

SET SERVEROUTPUT ON;
DECLARE
req UTL_HTTP.req;
resp UTL_HTTP.resp;
buffer VARCHAR2(32767);
l_data VARCHAR2(32767) := '{"inputs":"JE SUIS KHALID"}';
BEGIN
-- Prepare HTTP request
req := UTL_HTTP.begin_request(
url => 'https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-fr-en',
method => 'POST',
http_version => 'HTTP/1.1'
);

-- Set headers
UTL_HTTP.set_header(req, 'Content-Type', 'application/json');
UTL_HTTP.set_header(req, 'Authorization', 'Bearer xxxxxxxxxx');

-- Write JSON payload
UTL_HTTP.write_text(req, l_data);

-- Get HTTP response
resp := UTL_HTTP.get_response(req);

-- Read and print the response content
BEGIN

   LOOP  
       UTL\_HTTP.read\_text(resp, buffer);  
       DBMS\_OUTPUT.put\_line(buffer);  
   END LOOP;  
   DBMS\_OUTPUT.put\_line('hii ');  

EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('Exception ');

       DBMS\_OUTPUT.put\_line('❌ Error: ' || SQLERRM);  
       DBMS\_OUTPUT.put\_line('🔎 Detailed: ' || UTL\_HTTP.get\_detailed\_sqlerrm);  
       -- Try to clean up the response if open  
       BEGIN  
           UTL\_HTTP.end\_response(resp);  
       EXCEPTION  
           WHEN OTHERS THEN  
               DBMS\_OUTPUT.put\_line('⚠️  Failed to close response: ' || SQLERRM);  
       END;  

END;

-- Always end the response
UTL_HTTP.end_response(resp);

END;

this the error

DECLARE
*
ERROR à la ligne 1:
ORA-29273: échec de demande HTTP
ORA-06512: à "SYS.UTL_HTTP", ligne 1130
ORA-12535: TNS : le délai imparti à l'opération est écoulé
ORA-06512: à ligne 8

Comments
Post Details
Added 3 days ago
0 comments
13 views