Hi,

I am using Raspberry PI 3 Model B and have installed SQL Anywhere 17 on it. I am following SCN blogs which showed how to install SQL Anywhere and also connect to it via a Python program.

http://scn.sap.com/community/sql-anywhere/blog/2014/08/11/sql-anywhere-available-for-linux-on-arm

When I execute my python program, I get an error "Could not load dbcapi".

After installing SQL Anywhere, I used the below commands to set the PATH and create a new DB.

source "/home/pi/MySql/bin32/sa_config.sh"
dbsrv17 –v (returns 17.0.0.1063)
dbinit mysqlaDB.db -dba murali,sql123
dbsrv17 -ud mysqlaDB.db

I installed PIP and sqlanydb libraries using below commands

sudo apt-get install python-pip  
sudo pip install sqlanydb

I copied the sample code to test the python script. I already have pythoin 2.7.9 installed on my Raspberry PI.

import sqlanydb  
conn = sqlanydb.connect(uid=’murali’, pwd='sql123', eng='mysqlaDB', dbn='mysqlaDB' )  
curs = conn.cursor()  
curs.execute("select 'Hello, world!'")  
print "SQL Anywhere says: %s" % curs.fetchone()  
curs.close()  
conn.close()

Below are some information on my Path settings and System OS info.

pi@raspberrypi:~/Sample Code $ env | grep PATH
LD_LIBRARY_PATH=/home/pi/MySql/lib32:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0    PATH=/home/pi/MySql/bin32:/home/pi/MySql/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

NODE_PATH=/home/pi/MySql/node:

pi@raspberrypi:~/Sample Code $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL=http://www.raspbian.org/RaspbianBugs

However, I was able to use the terminal to connect to the newly created DB using the following commands.

dbspawn -f dbsrv17 -n mysqlaDB -o server.out mysqlaDB.db
dbisqlc

I started the demo DB and tried to use python script to connect to it. It gave me the same error message.

Below is the complete error message.

pi@raspberrypi:~/Sample Code $ sudo python MySQL01.py
Traceback (most recent call last):
  File "MySQL01.py", line 2, in <module>
    conn = sqlanydb.connect(uid='dba', pwd='sql', eng='demo', dbn='demo' )
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 522, in connect
    return Connection(args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 538, in __init__
    parent = Connection.cls_parent = Root("PYTHON")
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 464, in __init__
    'libdbcapi_r.dylib')
  File "/usr/local/lib/python2.7/dist-packages/sqlanydb.py", line 456, in load_library
    raise InterfaceError("Could not load dbcapi.  Tried: " + ','.join(names))
TypeError: sequence item 0: expected string, NoneType found

Thanks, Murali

asked 26 May '16, 07:41

Murali's gravatar image

Murali
68337
accept rate: 50%


Ah, yes! SUDO does not export the LD_LIBRARY_PATH environ or other environs unless included on the cmdline .....

You might be able to run it as sudo LD_LIBRARY_PATH=home/pi/MySql/lib32 python MySQL01.py or possibly sudo LD_LIBRARY_PATH=${LD_LIBRARY_PATH} python MySQL01.py

You can break SUDO security model http://serverfault.com/questions/371630/how-to-configure-sudoers-to-always-keep-ld-library-path-envrionment-variable but that wouled be unadviseable.

permanent link

answered 26 May '16, 15:36

Nick%20Elson%20SAP%20SQL%20Anywhere's gravatar image

Nick Elson S...
7.3k35107
accept rate: 31%

Thanks Nick. I will test it out. Cheers.

(27 May '16, 02:06) Murali

The fact that you are getting this error tends to confirm the Python 'driver' is installed, set up correctly, and is loading correctly.

The next thing to verify is if your installation has the library libdbcapi_r.so installed. And, if it does, verify the location of that is set in your LD_LIBRARY_PATH; this is usually set up for you when you run the sa_config.sh or sa_config.csh which is a required step.

permanent link

answered 26 May '16, 09:27

Nick%20Elson%20SAP%20SQL%20Anywhere's gravatar image

Nick Elson S...
7.3k35107
accept rate: 31%

edited 26 May '16, 09:32

Thanks Nick.

I can verify the existence of the file libdbcapi_r.so inside the lib32 folder. I sourced the file sa_config.sh. Hence below is my path which has the LD_LIBRARY_PATH set to the lib32 folder

pi@raspberrypi:~/Sample Code $ env | grep PATH
LD_LIBRARY_PATH=/home/pi/MySql/lib32:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
PATH=/home/pi/MySql/bin32:/home/pi/MySql/bin64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
NODE_PATH=/home/pi/MySql/node:
(26 May '16, 13:19) Murali

I found the problem. I was running the python program using SUDO command in the front. It seemed to have a problem. If I type in the command "python MySQL01.py" it works fine. I generally use sudo command when my python program access GPIO pins in my raspberry pi.

Thanks, Murali

(26 May '16, 13:46) Murali
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×16

question asked: 26 May '16, 07:41

question was seen: 645 times

last updated: 27 May '16, 02:06