import sqlpython gives TypeError: object of type 'NoneType' has no len() in

Skip to first unread message


Mar 17, 2010, 5:43:27 PM3/17/10
to sqlpython,
I get this error when trying to import sqlpython:

>>> import sqlpython
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 1, in <module>
import mysqlpy
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 11, in <module>
from sqlpyPlus import *
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 26, in <module>
import sys, os, re, sqlpython, pyparsing, re, completion
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 12, in <module>
import pyparsing, connections
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 216, in <module>
class DatabaseInstance(object):
File "C:\Python26\lib\site-packages\sqlpython-1.7.1-py2.6.egg
\sqlpython\", line 222, in DatabaseInst
pickledir = os.path.join(os.getenv('HOME'), '.sqlpython')
File "C:\Python26\lib\", line 96, in join
assert len(path) > 0
TypeError: object of type 'NoneType' has no len()

In case it matters, u' must go in front of some Oracle commands when
using cx_Oracle:
orcl = cx_Oracle.connect(u"uname", u"passwd", u"dcmd")
curs = orcl.cursor()
curs.execute(u'SELECT param, value FROM INIT_PARAMS')

Does anyone have suggestions on what to try next?


Mar 17, 2010, 5:59:56 PM3/17/10
to sqlpython
Looks like this is the same bug that was described at
(thread title: 'sqlpython relies on HOME env variable'). The easiest
workaround is to set the HOME environment variable to your
%USERPROFILE environment variable. Once HOME is defined,
os.path.join() will stop raising the exception. Longer term, I believe
Catherine may be working on a fix for the bug.

-- William


Mar 18, 2010, 10:04:26 AM3/18/10
to sqlpython
I'm running on WindowsXP so don't have a HOME or USERPROFILE
environment variable. Are there other workarounds?

I tried changing

pickledir = os.path.join(os.getenv('HOME'), '.sqlpython')

in to
pickledir = os.path.expanduser('~')
and got past the error, but now get an error when attempting to
connect to Oracle: SyntaxError: invalid syntax

Syntax used:
sqlpython oracle://username:password@res-hua:1521/dcmd

William McVey

Mar 18, 2010, 2:13:21 PM3/18/10
to Cynthia Pepper,
On Thu, Mar 18, 2010 at 1:09 PM, Cynthia Pepper <> wrote:
> You're right, there is a USERPROFILE, and I just set up a HOME environment
> variable, but that did not help.

When you add the HOME environment, it will be available to newly
launched (by the Windows UI) tools, but existing CMD.exe windows won't
necessarily pick up the new variable definition. Easiest would be to
log out and log back in, but you may be able to get the new shell
environment variable by starting a new cmd.exe window. I'm a lot less
familiar with Windows than I am with Linux, so I'm not entirely
certain if that'd explain it.

> I guess it might have something to do with Unicode.  When I use strings in
> cx_Oracle calls I have to prefix some strings with u as shown in the follow
> python script :
> import cx_Oracle
> orcl = cx_Oracle.connect(u"myUsername", u"myPassword", u"dcmd")
> curs = orcl.cursor()

This is somewhat unexpected. Unless dealing with something that has a
defined codec, most libraries will accept regular ole python strings
and not require unicode strings. Or if they do require unicode
strings, they will simply convert the string object into a unicode
object. If your Username, password, and other parameters are normal
ascii strings, creating them as unicode string objects shouldn't be
necessary, and I was able to find plenty of examples (on
and elsewhere) where the connection string for a cx_Oracle connection
was specified as a regular ole string. Even at
where the author of the cx_Oracle talks about the new unicode mode
(disabled by default on 2.x) where all passed strings are expected to
be unicode objects, the connect strings in the example are still
normal strings. What makes you think you need the unicode objects
rather than the normal string objects? Were you getting an error
without unicode strings? Could you paste the error (traceback and all)
so we can view what is happening

> I'm just learning Python, and will come back to this problem later after
> reading some more. Unicode is complicating this, maybe moving my code to
> Python3 would help? In the meantime I'm getting by with os.system calls to
> sqlplus.

Quite honestly, I think you'd probably run into *more* problems
related to unicode if you went to python 3. That's not to imply that
python 3 isn't worth moving to (it clearly is), but I wouldn't suggest
making the switch to bypass behaviour in python 2 that you can't
explain or don't fully understand.

-- William

P.S. The traceback for the SyntaxError you were experiencing would
still be useful. And, rather firing off sqlplus from system calls, I'd
highly recommend looking into SQLAlchemy for improved programatic
access to your DB.

Reply all
Reply to author
0 new messages