I need to validate that user provided data for oracle account information is correct. I tried to use cx_Oracle but the version of OCI.DLL that is on my servers (which I can't upgrade) seems to not be the correct version for cx_Oracle.
How can I validate username/passwords without using cx_Oracle?
If you can't compile cx_Oracle, you have two options:
use ODBC (for example PyODBC);
use subprocess to interact with sqlplus.
If you have access to the username & password hashes through some alternate means that doesn't require cx_Oracle, and simply need to verify the password hashes, the Passlib python library may be able to help. It supports both oracle10g and oracle11g hash formats.
The problem is most likely the version of your cx_Oracle module.
You have to be extremely careful when you install the module, to choose the appropriate version for your oracle installation.
http://cx-oracle.sourceforge.net/
If you can't connect to the database using cx_Oracle, you might have a hard time checking the accuracy of the information
If you have sql*plus installed, you might try to start a process using the subprocess module and check if you can connect, but in my opinion, you might be better of with fixing cx_Oracle
Edit: Meant the subprocess module.
Here is how can you do it with subprocess:
import subprocess
def is_login_valid(user, password, instance):
output = subprocess.check_output("sqlplus %s/%s#%s" %(user, password, instance))
return (output.find("ORA-01017") == -1 and output.find("ORA-12154") == -1)
Related
I was previously using python to pass multiple queries to an Oracle Database but the script took too long to execute. So I decided to opt for PyPy and use the JIT Compiler rather than the CPython interpreter. I installed PyPy via apt and then compiled the script with the command:
pypy script_file.py
It returned back the following error:
import cx_Oracle
ImportError: No module named cx_Oracle
Is cx_Oracle not supported by PyPy or am I doing something incorrectly? If it is, is this due to an issue with the environment values and how can I set it right?
Thank you for the help! Sorry for the bad English.
Regardless of PyPy support, each connection to Oracle Database will still only ever be able to execute one statement at a time. You could stick with CPython and look at other architectures such as opening multiple connections. Also tune your queries and tune how cx_Oracle fetches data, eg. with arraysize and the (new in cx_Oracle 8) prefetchrows. See the cx_Oracle manual section Tuning cx_Oracle.
I am trying to connect to an SQL Server from a version of python (pythonista) that requires that I use pure python drivers. I am able to connect using pytds if I don't use sqlalchemy so I know this works.
However, I would like to be able to use sqlalchemy so I installed sqlaclhemy-pytds but when I try:
engine = create_engine('mssql+pytds://' +various params)
I get:
Can't load plugin:
sqlalchemy.dialects:mmsql.pytds
What am I overlooking?
I finally got it working by adding:
https://github.com/m32/sqlalchemy-tds.git
I thought I got that when I did:
pip install sqlalchemy-pytds
pip install python-tds
especially since the pip list showed
python-tds (1.9.1) - Python DBAPI driver for MSSQL using pure Python TDS (Tabular Data Stream) protocol implementation
but apparently the sqlalchemy MSSQL dialect is different and is not available via pip and must be imported as sqlalchemy_tds
Thanks to everyone who replied.
According to the SQLAlchemy dialects page it looks like you'll need to use the external dialect here:
https://github.com/m32/sqlalchemy-tds
I have python 2.7.12 installed on my server. I'm using PuTTY to connect to my server. When running my python script I get the following.
File "home/myuser/python/lib/python2.7/site-packages/peewee.py", line 3657, in _connect
raise ImproperlyConfigured('pysqlite or sqlite3 must be installed.')
peewee.ImproperlyConfigured: pysqlite or sqlite3 must be installed.
I thought sqlite was installed with python 2.7.12, so I'm assuming the issue is something else. Haven't managed to find any posts on here yet that have been helpful.
I am missing something?
Thanks in advance
Peewee will use either the standard library sqlite3 module or, if you did not compile Python with SQLite, Peewee will look for pysqlite2.
The problem is most definitely not with Peewee on this one, as Peewee requires a SQLite driver to use the SqliteDatabase class... If that driver does not exist, then you need to install it.
I have been trying for the past several hours to find a working method of accessing a mysql database in python. The only thing that I've managed to get to compile and install is pyodbc but the necessary driver is not available for ppc leopard.
I already know about this.
UPDATE:
I've gotten setuptools to install, but now MySQL-python won't build.
UPDATE:
Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.
Try SQL Alchemy.
It is awesome.
Install fink. It includes the MySQLdb package.
UPDATE: Now I've gotten sqlalchemy to
install but while it will show up when
called by the command line it won't
import when used in my cgi script.
Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.
What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.
Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.
I can get Python to work with Postgresql but I cannot get it to work with MySQL. The main problem is that on the shared hosting account I have I do not have the ability to install things such as Django or PySQL, I generally fail when installing them on my computer so maybe it's good I can't install on the host.
I found bpgsql really good because it does not require an install, it's a single file that I can look at, read and then call the functions of. Does anybody know of something like this for MySQL?
MySQLdb is what I have used before.
If you host is using Python version 2.5 or higher, support for sqlite3 databases is built in (sqlite allows you to have a relational database that is simply a file in your filesystem). But buyer beware, sqlite is not suited for production, so it may depend what you are trying to do with it.
Another option may be to call your host and complain, or change hosts. Honestly these days, any self respecting web host that supports python and mysql ought to have MySQLdb pre installed.
I don't have any experience with http://www.SiteGround.com as a web host personally.
This is just a guess, but it's common for a shared host to support Python and MySQL with the MySQLdb module (e.g., GoDaddy does this). Try the following CGI script to see if MySQLdb is installed.
#!/usr/bin/python
module_name = 'MySQLdb'
head = '''Content-Type: text/html
%s is ''' % module_name
try:
__import__(module_name)
print head + 'installed'
except ImportError:
print head + 'not installed'
I uploaded it and got an internal error
Premature end of script headers
After much playing around, I found that if I had
import cgi
import cgitb; cgitb.enable()
import MySQLdb
It would give me a much more useful answer and say that it was not installed, you can see it yourself -> http://woarl.com/db.py
Oddly enough, this would produce an error
import MySQLdb
import cgi
import cgitb; cgitb.enable()
I looked at some of the other files I had up there and it seems that library was one of the ones I had already tried.
You could try setting up your own python installation using Virtual Python. Check out how to setup Django using it here. That was written a long time ago, but it shows how I got MySQLdb setup without having root access or anything like it. Once you've got the basics going, you can install any python library you want.
You really want MySQLdb for any MySQL + Python code. However, you shouldn't need root access or anything to use it. You can build/install it in a user directory (~/lib/python2.x/site-packages), and just add that to your PYTHON_PATH env variable. This should work for just about any python library.
Give it a shot, there really isn't a good alternative.
Take a pick at
https://docs.djangoproject.com/en/1.8/ref/databases/
MySQLdb is mostly used driver, but if you are using python3 and django 1.8.x that will not work, then you should use mysqlclient that is a folk of MySQLdb on the following link
https://pypi.python.org/pypi/mysqlclient