Teradata pypyodbc SQL_INVALID_HANDLE - python

While connecting pypyodbc with teradata i am getting SQL_INVALID_HANDLE
OS - Red Hat 4.4.7-17
Python Version - 2.6.6
I am not having administrative privilages to install the pypyodbc so i have downloaded the module, set pythonpath and imported it.
Done the required exports to point the python module to find the correct libodbc.so
export LD_LIBRARY_PATH=/opt/teradata/client/15.10/odbc_64/lib/
export ODBCINST=/opt/teradata/client/ODBC_64/odbcinst.ini
export ODBCINI=/opt/teradata/client/ODBC_64/odbc.ini
used the below code to create a db connection
pypyodbc.connect("Driver={Teradata};DBCNAME=<DB>;UID=<UNAME>;PWD=<PASS>")
The odbc connection string i have used is correct. I have tested using the below approach
/opt/teradata/client/15.10/bin/tdxodbc64 -C "Driver={Teradata};DBCNAME=<DB>;UID=<UNAME>;PWD=<PASS>"
**Note:**I am not using teradata OOTB python module because it works with a higher version of python which i cannot install.
Error
File "<stdin>", line 1, in <module>
File "<LOCAL_PATH>/pypyodbc.py", line 2421, in __init__
AllocateEnv()
File "<LOCAL_PATH>/pypyodbc.py", line 1000, in AllocateEnv
check_success(SQL_NULL_HANDLE, ret)
File "<LOCAL_PATH>/pypyodbc.py", line 990, in check_success
ctrl_err(SQL_HANDLE_ENV, ODBC_obj, ret, False)
File "<LOCAL_PATH>/pypyodbc.py", line 970, in ctrl_err
raise ProgrammingError('', 'SQL_INVALID_HANDLE')
pypyodbc.ProgrammingError: ('', 'SQL_INVALID_HANDLE')
any guidance on the matter is helpful

You need to install some packages. You can use this command:
sudo yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
This wiki will help you.
https://github.com/mkleehammer/pyodbc/wiki

Related

python 3.9 and rdflib keep changing slashes in a url

I am completely new in Python . I am using 3.9.2 and rdflib . I try to execute the first example,
from rdflib import Graph
g = Graph()
g.parse('http://dbpedia.org/resource/Semantic_Web')
for s, p, o in g:
print(s, p, o)
I create a py file , paste it in and then using windows 10 cmd, I cd to my pyhton file and do python rdftest.py.
No matter how I set the url, I get
Traceback (most recent call last):
File "D:\BACKUP\programming\rdftrest.py", line 3, in <module>
g.parse('http://dbpedia.org/resource/Semantic_Web')
File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\graph.py", line 1188, in parse
source = create_input_source(
File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\parser.py", line 281, in create_input_source
) = _create_input_source_from_location(
File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\site-packages\rdflib\parser.py", line 312, in _create_input_source_from_location
if path.exists():
File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1407, in exists
self.stat()
File "C:\Users\spiro\AppData\Local\Programs\Python\Python39\lib\pathlib.py", line 1221, in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is
incorrect: 'http:\\dbpedia.org\\resource\\Semantic_Web'
How can I fix that? Thank you
It seems to be a bug in rdflib version 6.0.0. I confronted the same problem and the solution was to downgrade the version to 5.0.0. Then it seems to work fine.
Looks like the parse() function is messed up: it uses pathlib when it sees URL and urllib when it sees the file path.
The issue seems to be related to how your Python is set up.
On Mac and Windows I can just:
install Python 3.9 (or 3.8, 3.7 or 3.6)
install rdflib 6.0.0
C:\Users\nick\AppData\Local\Programs\Python\Python39\python.exe -m pip install rdflib
run the script using Python with rdflib now installed
C:\Users\nick\AppData\Local\Programs\Python\Python39\python.exe rdftest.py
This works fine on up-to-date Windows 10 on both the Command Prompt and on Powershell.
So this issues seems to be to do with your Python installation or Windows configuration, not rdflib per se.

Unable to run Python interpreter in terminal, through Anaconda3

When I try the "python" or "python3" command to run the interpreter, this is the error am getting.
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
main()
File "/usr/lib/python3.5/site.py", line 566, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
Output to which python
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ which python
/usr/bin/python
Output to python -V
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python -V
Python 3.5.2 :: Continuum Analytics, Inc.
Could you tell me the reason of this error and how can I remove it?
I found this link while looking for the solution, but it didnt make any difference.
I guess configuring_apache_django_anaconda is relevant, if you look at the troubleshooting section.
This means that apache is using Python 2 instead of Python 3 to run a program that is designed for Python 3 only, and fails because Python 2 does not have the _sysconfigdata_m module. The solution is to add the following file to your apache envvar file (/etc/apache2/envvar):
export PATH=/opt/anaconda3/bin:$PATH
So maybe check which version of python anaconda is running?
Also these two might be related:Linux - Weird Python Output
ubuntu anaconda suggested fix
I would suggest you print your PATH variable to see if you have several python3 entries in there, and try to specify explicity which one to run.
That is an strange situation you have gotten yourself into, and if Continuum had any part of it (where I'm an engineer) we'd like to understand what we did that led to it so we can avoid it in the future.
Where did you try installing Anaconda? Did you set any environment variables?
The "easiest-to-resolve" cause of this problem is that you have set some environment variables that are mixing system Python libraries and Anaconda Python libraries. You should look at the output of:
env | grep -i anaconda
and see if anything comes up that specifies a path to Anaconda. The only one that should appear is an entry in PATH. If there are any LD_LIBRARY_PATH, PYTHONPATH, PYTHONHOME or similar environment variables that point to Anaconda then that is going to be a problem.
The only other thing I can think of is that you specified /usr as the install path for Anaconda. If that is the case you are probably in for a world of pain: you have just replaced your system Python with Anaconda. You should investigate how to force-reinstall whichever Python package comes with your *nix distribution, but even that might be tricky: tools such as yum are written in Python and will need a working system Python interpreter to work. But RPM is binary (if you're on a RedHat or derivative distro), so maybe you can wget or curl the necessary system Python packages and force-install them to try and fix things.
Let us know if that is enough information for you to fix things or at least identify the source of the problem a little better.

no module named requests

I will first state I have searched for this problem, and found the exact same problem here ( ImportError: No module named 'requests' ) but that hasn't helped me.
I am using macports on osx (mountain lion). I have successfully installed and run a few scripts without any issues.
from the macports page, I have installed requests via the method it detailed and as far as I can tell, it has installed successfully:
daves-mbp:~ Dave$ port search requests
arpwatch #2.1a15 (net)
Monitor ARP & RARP requests
http_ping #29jun2005 (net, www)
Sends HTTP requests every few seconds and times how long they take
httping #2.0 (net, www)
Ping-like tool for http-requests
py-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py26-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py27-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py31-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py32-requests #1.2.3 (python, devel)
Python HTTP for Humans.
py33-requests #1.2.3 (python, devel)
Python HTTP for Humans.
webredirect #0.3 (www)
small webserver which redirects all requests
Found 10 ports.
I have python 2.7, so I installed it via:
daves-mbp:~ Dave$ sudo port install py27-requests
Password:
---> Computing dependencies for py27-requests
---> Fetching archive for py27-requests
---> Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2 from http://jog.id.packages.macports.org/macports/packages/py27-requests
---> Attempting to fetch py27-requests-1.2.3_0.darwin_12.noarch.tbz2.rmd160 from http://jog.id.packages.macports.org/macports/packages/py27-requests
---> Installing py27-requests #1.2.3_0
---> Activating py27-requests #1.2.3_0
---> Cleaning py27-requests
---> Updating database of binaries: 100.0%
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
daves-mbp:~ Dave$
I think that looks good. Using macports is there something else I have to do before using it? I thought the python setup.py install (in the aforementioned post) may have solved my problem, however, when I search for requests in my filesystem, the only reference is burried in a path (that macports says is a store for user installed modules. And besides, there is no setup.py within that or it's parent directory.
I have restarted my terminal window (that fixed another problem earlier), but it made no difference here.
Any help is appreciated
edit:
which python reports /opt/local/bin/python
the first lines of the python interpreter DID report:
daves-mbp:~ Dave$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
but now I have done something and it's responding with new errors:
daves-mbp:~ Dave$ python
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 548, in <module>
main()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
In trying to sort this out, I have broken python, and eventually I got it going again.
I think initially I had not run one of the port select --set... commands. Once I realised this might be the case, I did so, but that produced the errors at the top. MAXREPEATS, a circular reference perhaps? No idea.
I have read here (macports didn't place python_select in /opt/local/bin) and here (How do I uninstall python from OSX Leopard so that I can use the MacPorts version?) about the --set command not working and to try sudo port select python python26 (i used python27) instead.
I checked the PATH and python didn't appear, so I updated that as well.
I got my python interpreter back and low-and-behold imports requests now works.
I think at the end of it all, there were two errors:
I used --set instead of the newer command, and
my path wasn't set
edit: Actually, after more debugging, I found the error was on the first line of my script, I had defined which python to use (which was the default apple one, which doesn't include the module). Once I updated the shebang line, it worked.

Pymongo Installation & Executing on MacOS

May i know why i couldn't run the pymongo on MacOS? I installed the pymongo with
sudo easy_install pymongo
but i not sure why will i getting this error
conn = Connection(ip)
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/connection.py", line 180, in __init__
File "/Library/Python/2.7/site-packages/pymongo-2.4.2-py2.7-macosx-10.8-intel.egg/pymongo/mongo_client.py", line 269, in __init__
pymongo.errors.ConnectionFailure: could not connect to 192.168.0.1:27017: [Errno 51] Network is unreachable
thus i google and found i haven't initiate the pymongo yet, then i tried to run
mongod
mongo
./mongod
then it returned me command not found. tried to execute this
sudo export PATH=$PATH:/usr/local/mongodb/bin
Anyone know what's happening to my installation and how could i fix it? Thanks.
You have to install the mongodb server for osx: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

Having an issue with setting up MySQLdb on Mac OS X Lion in order to support Django

So I am pretty sure that I have managed to dork up my MySQLdb installation. I have all of the following installed correctly on a fresh install of OS X Lion:
phpMyAdmin
MySQL 5.5.16
Django 1.3.1
And yet when I try to run "from django.db import connection" in a django console, I get the following:
from django.db import connection Traceback (most recent call
last): File "", line 1, in File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/init.py",
line 78, in
connection = connections[DEFAULT_DB_ALIAS] File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py",
line 93, in getitem
backend = load_backend(db['ENGINE']) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py",
line 33, in load_backend
return import_module('.base', backend_name) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py",
line 35, in import_module
import(name) File
"/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/backends/mysql/base.py",
line 14, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/[my
username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so,
2): Library not loaded: libmysqlclient.18.dylib Referenced from:
/Users/[my
username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found
I have no idea why this is happening, could somebody help walk me through this?
I found the following solution for this issue. It worked for me. I have encountered this problem when I was running python console from PyCharm.
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Easy,
edit your .bash_profile (vi ~/.bash_profile) somewhere in that add the following line:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
This line assumes your mysql install directory is in /usr/local/mysql/.
This will solve executing via python interrupter launched in shell (the .bash_profile exports the path needed by the MySQLdb module to load the ' libmysqlclient.18.dylib').
If you are having this issue with a Python IDE like PyCharm add the DYLD_LIBRARY_PATH variable to the launching module configuration.
I hope this helps :)
Also,
To fully understand this problem, read the following section:
http://mysql-python.sourceforge.net/FAQ.html#importerror
This explains this error in detail
Install pip if you haven't already, and run
pip install MySQL-Python

Categories