UTL_HTTP error [message #614163] |
Sun, 18 May 2014 00:52 |
|
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 #614167 is a reply to message #614165] |
Sun, 18 May 2014 01:31 |
|
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 #614177 is a reply to message #614174] |
Sun, 18 May 2014 03:08 |
|
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 |
|
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 #614189 is a reply to message #614184] |
Sun, 18 May 2014 05:43 |
|
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 #614192 is a reply to message #614163] |
Sun, 18 May 2014 07:41 |
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 |
|
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.
|
|
|