Re: Django & Oracle connection problem

420 views
Skip to first unread message

akaariai

unread,
Jan 25, 2013, 1:40:05 AM1/25/13
to Django users
On 25 tammi, 00:27, Dylan Klomparens <dylan.klompar...@gmail.com>
wrote:
> I have a Django program that is connecting to an Oracle database. In my
> settings.py file I have this configuration:
>
> DATABASES = {
>   'default': {
>     'ENGINE': 'django.db.backends.oracle',
>     'NAME': 'xe',
>     'USER': 'MY_USER_NAME',
>     'PASSWORD': 'abcdefghijklmnopqrstuvwxyz',
>     'HOST': 'db_server.example.com',
>     'PORT': '1234',
>   }}
>
> I received a strange error when attempting to load the website:
>
> ORA-28547: connection to server failed, probable Oracle Net admin error
>
> After further investigation, I sniffed the TCP traffic between the
> webserver and the database server. I discovered this text in the network
> communication, which I reformatted for this post:
>
> (DESCRIPTION=
>     (ADDRESS=
>         (PROTOCOL=TCP)
>         (HOST=1.2.3.4)
>         (PORT=1234)
>     )
>     (CONNECT_DATA=
>         (SID=xe)
>         (CID=
>             (PROGRAM=httpd@webserver_hostname)
>             (HOST=webserver_hostname)
>             (USER=apache)
>         )
>     ))
>
> So my question is: why is Django attempting to connect to the Oracle
> database with different credentials than the ones I specified? Notably, it
> is attempting to use user 'apache' instead of 'MY_USER_NAME'. The database
> host IP, port, and SID are correct and what I specified. It just appears to
> be the user name that is different.
>
> (As a side note, I suppose the password is transmitted separately in a
> later portion of the log in process?)

My understanding is that the USER in there isn't the username for
Oracle login, it is the username of current user running the program.
If everything else is OK but you have wrong username you should get an
error telling you that username or password was incorrect.

- Anssi

Dan Gentry

unread,
Jan 25, 2013, 8:27:38 AM1/25/13
to django...@googlegroups.com
You've probably already tried the simple things:

  • Confirm that the server name and port are correct.
  • Ensure that firewall/routing rules will allow the connection.
  • Try a simple connection on the same box with sqlplus.

Walking through this list has helped me a number of times.

Dylan Klomparens

unread,
Jan 25, 2013, 9:29:49 AM1/25/13
to django...@googlegroups.com
Hmm, ok so I guess having a different user name isn't causing the problem. I was able to connect to the database from the webserver using SQL Developer, and I am sure the credentials are correct. Are there any configuration steps that I need to perform for Instant Client or cx_Oracle? So far, I have just added the shared library path to the loader so that Instant Client can run (i.e. change LD_LIBRARY_PATH environment variable). Is there anything else I need to do to configure Instant Client to work with Django?

Dylan Klomparens

unread,
May 15, 2013, 9:07:35 AM5/15/13
to django...@googlegroups.com
This bug was filed as ticket 19720 (https://code.djangoproject.com/ticket/19720) and resolved. It should not be a problem if you are using version 1.4.* or 1.5.* of Django. Additionally, the fact that you get the same information when you attempt to login with another SQL client leads me to believe there is something about the database is not set up right.

-- Dylan


On Wed, May 15, 2013 at 5:43 AM, Michael Van <fanli...@gmail.com> wrote:
I have the same error when python managment runserver  :
cx_Oracle.DatabaseError: ORA-28547: connection to server failed, probable Oracle Net admin error
and this Error infomation is the same when I type sqlplus try to login.
My os is Xubuntu13.10, and I installed oracle-instance on ubuntu, 
so I think that the instance is somewhere error, but I don't konw where it is.
>_<
在 2013年1月25日星期五UTC+8上午6时27分22秒,Dylan Klomparens写道:
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/WnLejpFfUsE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.

Dylan Klomparens

unread,
May 15, 2013, 9:24:55 AM5/15/13
to django...@googlegroups.com
Oops! I was thinking about a different problem, and realized that I gave you some bad information. Please disregard the last message.

I will paste some of the installation instructions for the Oracle Full Client I wrote up for my organization:

Create a Linux user called 'oracle'.
Create the directory /client and set its ownership to oracle:oracle. This is where the Oracle client will be installed.
Install Oracle client:
Log in as user oracle
Copy the Oracle Full Client install package to /tmp, unzip it, and run the installer: /tmp/client/runInstaller
Select the 'Administrator' installation option
Set the Oracle Base to /client/oracle/product/11.2.0 and the Software Location to /client/oracle/product/11.2.0/db
Leave the Inventory Directory as the default: /client/oracle/product/oraInventory
Leave the oraInventory Group Name as the default: oracle
Install pre-requisite packages and scripts noted in the installation process...
(Note that the "pdksh" library is a little hard to find. You can get it here: http://rpmfind.net/linux/rpm2html/search.php?query=pdksh)
Execute the installation
Now you'll need to fix some linking errors...
To fix Oracle library linking:
Navigate to /client/oracle/product/11.2.0/db/lib/
Remove file libexpat.so.1
As user oracle:
Create a symbolic link: libexpat.so.1 --> libexpat.so.1.5.2
As root:
Create a file called 'oracle.sh'. It should contain these two lines:
export ORACLE_HOME=/client/oracle/product/11.2.0/db # Note, you may need to change the version number here to match your client version. export PATH=$PATH:$ORACLE_HOME/bin

Move 'oracle.sh' to /etc/profile.d/
Add a line "LD_LIBRARY_PATH=/client/oracle/product/11.2.0/db/lib/" to /etc/sysconfig/httpd

Every time apache is started it will set LD_LIBRARY_PATH specifically it. That way, LD_LIBRARY_PATH isn't set globally.

All done! Hope this helps!

Jani Tiainen

unread,
May 16, 2013, 4:21:16 AM5/16/13
to django...@googlegroups.com
If you want just to connect Oracle but not run server locally using instant client is much more easier option to setup.

On Wed, 15 May 2013 02:43:36 -0700 (PDT)
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages