Home » SQL & PL/SQL » SQL & PL/SQL » UTL_HTTP error
UTL_HTTP error [message #614163] Sun, 18 May 2014 00:52 Go to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member
DAER All,

I've this error when I run the function func_utl
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL)
--------------------------

My ORACLE version is:11.2.0.1.0



Step by step I do these:
1)
user creation:
-- Create the user
create user user_utl
identified by user_utl
default tablespace USERS
temporary tablespace TEMP
profile DEFAULT;
-- Grant/Revoke role privileges
grant connect to user_utl;
grant resource to user_utl;
----------------------------------------------
2)
connect as sysdba:
grant execute on utl_http to user_utl
----------------------------------------------
3)add and assign acl to user

create or replace function add_acl(url in String) return varchar2 is

l_acl_name varchar2(100) := 'utl_http.xml';
begin
begin
dbms_network_acl_admin.drop_acl(
acl => l_acl_name
);
exception
when others then null; -- ACL does not exist yet
end;

-- Privilege to connect to a host
dbms_network_acl_admin.create_acl(
acl => l_acl_name,
description => 'HTTP Access',
principal => 'user_utl',
is_grant => TRUE,
privilege => 'connect');

-- Privilege to resolve a hostname (DNS lookup)
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => l_acl_name,
principal => 'user_utl',
is_grant => TRUE,
privilege => 'connect',
position => null );
COMMIT;

-- Privilege to connect to yahoo
dbms_network_acl_admin.assign_acl(
acl => l_acl_name,
host => '*yahoo.com*',
lower_port => 80,
upper_port => 10000 );

commit;

end add_acl;
------------------------------------------------
4)
connect as user=user_utl

create or replace function func_utl(url in String) return varchar2 is

begin
DECLARE
l_url VARCHAR2(50) := 'http://yahoo.com';
l_http_request UTL_HTTP.req;
l_http_response UTL_HTTP.resp;

BEGIN
-- Make a HTTP request and get the response.

l_http_request := UTL_HTTP.begin_request(l_url);
l_http_response := UTL_HTTP.get_response(l_http_request);
UTL_HTTP.end_response(l_http_response);

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SUBSTR(SQLERRM,1,2000));
RETURN 'N';

END;

end func_utl;
-------------------------------------------------

When I execute the function: func_utl I get the above error


Thanks in advance for any suggestions
Re: UTL_HTTP error [message #614165 is a reply to message #614163] Sun, 18 May 2014 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
exception
when others then null; -- ACL does not exist yet
end;

Quote:
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SUBSTR(SQLERRM,1,2000));
RETURN 'N';


BUGS! Read WHEN THERS
Remove that and copy and paste your SQL*Plus session, in text mode NO images.
Before, Please How to use [code] tags and make your code easier to read.

Re: UTL_HTTP error [message #614167 is a reply to message #614165] Sun, 18 May 2014 01:31 Go to previous messageGo to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member
Thanks for your reply,
I checked the WHEN OTHERS THEN clause, but they worked fine. After running the add_acl I have record in Tables dba_network_acl_privileges, dba_tab_privs.
SELECT acl,
       principal,
       privilege,
       is_grant,
       TO_CHAR(start_date, 'DD-MON-YYYY') AS start_date,
       TO_CHAR(end_date, 'DD-MON-YYYY') AS end_date
FROM   dba_network_acl_privileges;

--------------
SELECT grantee , table_name , privilege
from dba_tab_privs
where table_name = 'UTL_HTTP'


Re: UTL_HTTP error [message #614169 is a reply to message #614167] Sun, 18 May 2014 01:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I checked the WHEN OTHERS THEN clause, but they worked fine.


Wrong! they are bugs. Read the link I gave you.

Post what I requested.

Re: UTL_HTTP error [message #614172 is a reply to message #614169] Sun, 18 May 2014 01:57 Go to previous messageGo to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member
How can I get SQL*Plus session, in text mode NO images.
Re: UTL_HTTP error [message #614174 is a reply to message #614172] Sun, 18 May 2014 02:42 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Just select the text, copy it and paste it.

Re: UTL_HTTP error [message #614177 is a reply to message #614174] Sun, 18 May 2014 03:08 Go to previous messageGo to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member
I removed WHEN OTHERS THEN clause
After running the function I received the this error:
Quote:

Connected.
SQL> execute FUNC_UTL ('http://yahoo.com');
BEGIN FUNC_UTL('http://yahoo.com');
END;
*
ERROR at line 1:
ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1130
ORA-24247: network access denied by access control list (ACL) ORA-06512: at " USER_UTL.FUNC_UTL", line 11
ORA-06512: at line 1

[Updated on: Sun, 18 May 2014 03:08]

Report message to a moderator

Re: UTL_HTTP error [message #614181 is a reply to message #614177] Sun, 18 May 2014 04:27 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This piece of code:
-- Privilege to resolve a hostname (DNS lookup)
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
  acl       => l_acl_name,
  principal => 'user_utl',
  is_grant  => TRUE,
  privilege => 'connect',
  position  => null );

Look what you've said: "Privilege to resolve a hostname". What you did? You granted "privilege => 'connect'". Try to grant RESOLVE instead (as you already granted CONNECT while creating ACL)
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
  acl       => l_acl_name,
  principal => 'user_utl',
  is_grant  => TRUE,
  privilege => 'resolve',          --> here!
  position  => null );

and then run the procedure again.
Re: UTL_HTTP error [message #614182 is a reply to message #614181] Sun, 18 May 2014 04:41 Go to previous messageGo to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member

I edited the procedure and compiled it and run it, but I got the same error
I don't know what is wrong
Re: UTL_HTTP error [message #614184 is a reply to message #614182] Sun, 18 May 2014 05:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Copy and paste what you have, ALL what you did and got INCLUDING ALL objects creation.
Use code tags as explained in the link I pointed you to.

Re: UTL_HTTP error [message #614189 is a reply to message #614184] Sun, 18 May 2014 05:43 Go to previous messageGo to next message
ora_meh
Messages: 6
Registered: May 2014
Junior Member
1)User Creation
create user test_utl
  identified by test_utl
  default tablespace USERS
  temporary tablespace TEMP
  profile DEFAULT;
-- Grant/Revoke role privileges 
grant connect to test_utl;
grant resource to test_utl;




2)Grant execution privilege to the user

grant execute on utl_http to test_utl




3)Add ACL

create or replace function add_acl(url in String) return varchar2 is

l_acl_name varchar2(100) := 'utl_http.xml';
begin

       begin
        dbms_network_acl_admin.drop_acl(
          acl =>         l_acl_name
        );
--      exception  when others then null; -- ACL does not exist yet
      end;
     
        -- Privilege to connect to a host
        dbms_network_acl_admin.create_acl(
        acl =>         l_acl_name,
        description => 'HTTP Access',
        principal =>   'test_utl',
        is_grant =>    TRUE,
        privilege =>   'connect');

       -- Privilege to resolve a hostname (DNS lookup)
        DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
          acl       => l_acl_name,
          principal => 'test_utl',
          is_grant  => TRUE,
          privilege => 'resolve',
          position  => null );

        commit;        

      dbms_network_acl_admin.assign_acl(
        acl =>         l_acl_name,
        host =>        '*yahoo.com*',
        lower_port => 80,
        upper_port => 10000 );

 commit;    

end add_acl;



4)Procedure Creation for user:test_utl
The owner of This procedure is test_utl

create or replace procedure my_utl(pUrl VARCHAR2) is
  begin
  DECLARE
  l_url            VARCHAR2(50) := pUrl;
  l_http_request   UTL_HTTP.req;
  l_http_response  UTL_HTTP.resp;

BEGIN
  -- Make a HTTP request and get the response.
  l_http_request  := UTL_HTTP.begin_request(l_url);
  l_http_response := UTL_HTTP.get_response(l_http_request);
  UTL_HTTP.end_response(l_http_response);


END;

end ;




conn test_utl/test_utl
and then run the procedure

5)Procedure Execution

execute my_utl('http://yahoo.com');------->> here I got error

[Updated on: Sun, 18 May 2014 05:47]

Report message to a moderator

Re: UTL_HTTP error [message #614190 is a reply to message #614189] Sun, 18 May 2014 06:17 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You create the procedure add_acl but you never executed it so acl are not granted.

In addition, TEST_UTL should be in upper case in the ACL procedure calls.

Re: UTL_HTTP error [message #614192 is a reply to message #614163] Sun, 18 May 2014 07:41 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
I do not know how got as far as you did: I can't even create the ACL, because you have the user name in lower case:

 32  commit;
 33* end add_acl;
orclz> /

Function created.

orclz> select add_acl('garb') from dual;
select add_acl('garb') from dual
       *
ERROR at line 1:
ORA-46238: Database user or role '"user_utl"' does not exist
ORA-06512: at "SYS.XS_ADMIN_UTIL", line 70
ORA-06512: at "SYS.XS_ACL_INT", line 114
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_NETWORK_ACL_ADMIN", line 503
ORA-06512: at "SYS.ADD_ACL", line 12


orclz>



--update: sorry, I see Michel has picked up on this already.

[Updated on: Sun, 18 May 2014 07:42]

Report message to a moderator

Re: UTL_HTTP error [message #614194 is a reply to message #614192] Sun, 18 May 2014 08:35 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Yes, OP did not see this error because he did not execute the function that creates or tries to create the ACL.

@ora_meh, this is why we ask you post the complete and not you just tell us what you think you did.

Previous Topic: Rolls limit
Next Topic: Oracle form error 06502
Goto Forum:
  


Current Time: Thu Apr 25 14:03:34 CDT 2024