cx_Oracle silently crashes on connect in python 2.7 - python

I use Windows 7, 64bit, with installed Python 2.7 and Oracle instant client 10.2.0.3.
I try to set up connection with Oracle database from python. In order to do this, I download cx_Oracle-5.1.2-10g.win32-py2.7.msi and install it.
upd. it's an error. i meant cx_Oracle-5.1.2-10g.win-amd64-py2.7.msi
Then I try to connect use code like this
import cx_Oracle
ad = cx_Oracle.makedsn('127.0.0.1', '1521', 'XE')
con = cx_Oracle.connect('user', 'password', ad)
And check that connection is set up correctly by selecting some rows from database table.
And at this moment happens something interesting.
I perform described actions in three different environments: Sublime Text 3, Python Console and ipython.
The problem is in ST3 and in ipython this chunk of code silently crashes on line with cx_Oracle.connect (I checked that with print statement in different places).
But in python console and idle it works just fine. Moreover sometimes it works properly in ipython, but I cannot understand why and when. In ST3 it never works.
ST shows message [Finished in 0.4s with exit code 3221226356]
To demonstrate behavior in python and ipython console I attach copypaste of simple case from cmd. It just exits from ipython.
C:\Users\Alexey>python
Python 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> cx_Oracle.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cx_Oracle.DatabaseError: ORA-12560: TNS:protocol adapter error
>>> exit()
C:\Users\Alexey>ipython
Python 2.7.7 (default, Jun 1 2014, 14:21:57) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import cx_Oracle
In [2]: cx_Oracle.connect()
C:\Users\Alexey>
Where is the problem? How can I solve it?
Thanks in advance.
PS. I tried to handle exception in ST3 and ipython such as
try:
cx_Oracle.connect()
except Exception as e:
print e
but script terminates on cx_Oracle.connect() and no message appears.

I tried this environment myself and did not experience the same behavior. Perhaps use faulthandler or gdb or some equivalent to figure out where the crash is taking place? cx_Oracle is still maintained (by me) so if you can find a bug I'll happily fix it! It may also be a problem with IPython or ST3 or in some interaction between these two and cx_Oracle. Since I can't replicate the problem, however, you'll need to provide a stack trace of some sort so we can proceed further.

Related

Trying to use win32ui with pywin32 gives: A dynamic link library (DLL) initialization routine failed

I am trying to use the win32ui module from pywin32 (yes i have the correct version).
My win32gui module does work fine but the ui module give me and error.
I have already tried:
reinstalling python,
adding PYTHON_PATH too system vars,
running the after install pywin32 script,
For the rest I am kinda of out thing i can try to do.
Python version: 3.9 (64 bit)
Pywin32 version: pywin32-228.win-amd64-py3.9 (is the .exe file name i don't know how to find the version)
just to clear up my only code is:
import win32ui
(this is my first question so i hope i have done this right)
Update
Applied the (below) fix (and a couple of more) to the original sources, built them, and uploaded the .whls to [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v228. But, since this bug is kind of a "deal breaker" (and there are 4+ months since v228 was released), I'm expecting v229 very soon (in the next days or so).
Check the Install steps section from (the beginning of) [SO]: PyWin32 and Python 3.8.0 (#CristiFati's answer) for details on how to install the .whls.
It's constantly reproducible on:
Python 3.9 64bit and 32bit (works on older versions)
PyWin32 228 (and older)
[cfati#CFATI-5510-0:e:\Work\Dev\GitHub\CristiFati\pywin32\src]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.09.00_test0\Scripts\python.exe"
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32ui
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\Install\pc064\Python\Python\03.09.00\Lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed
>>> import win32api
I did some debugging (created a VStudio 2015 solution (with 2 projects: for Python 3.9 and Python 3.8) for win32ui), and it turns out it's an Access Violation (segfault). The "best" part is that it's occurring before DllMain.
One of the last lines that I could get the debugger in, was [GitHub]: mhammond/pywin32 - (b228) pywin32/Pythonwin/win32RichEdit.cpp#225:
PyCCtrlView_Type PyCRichEditView::type("PyCRichEditView", &PyCCtrlView::type, &PyCRichEditCtrl::type,
RUNTIME_CLASS(CRichEditView), sizeof(PyCRichEditView),
PYOBJ_OFFSET(PyCRichEditView), PyCRichEditView_methods,
GET_PY_CTOR(PyCRichEditView));
This is a static member. Since the 2nd and 3rd arguments are also static members (wasn't paying attention to the fact that they're pointers), I thought it was [ISOCPP]: What’s the “static initialization order ‘fiasco’ (problem)”?, and I chased some ghosts.
Anyway, today I noticed [GitHub]: mhammond/pywin32 - Ensure we hold the GIL as win32ui initializes and calls back into Python (and from there [GitHub]: mhammond/pywin32 - Import win32ui broken on Python 3.9 that it's addressing).
Applying the patch, fixes the problem:
[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.09.00_test0\Scripts\python.exe"
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32ui
>>> import win32api

How can I use __future__ division in the IDLE startup file

In Python 2.7, how can I make the IDLE app use \__future__ division without typing from \__future__ import division manually every time I start IDLE?
If I put from \__future__ import division at the top of my .idlestartup file it is ignored, even though the other things in .idlestartup get executed. For example:
~> cat >.idlestartup
from __future__ import division
print("Executing .idlestartup")
~> idle -s
Here's what my IDLE window looks like after I try dividing:
Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>
Executing .idlestartup
>>> 2/3
0
>>>
I am using Mac OS X 10.9.5 Mavericks (also had the same problem on earlier versions of OS X). Note that the command line version above was included to make it easier to show what I'm talking about, but the version I'm more interested in is running the IDLE app from the GUI.
The solution suggested by Ashwini Chaudhary below worked for running the Anaconda version from the command line but not for running the IDLE app.
I was finally able to get future division working automatically in the IDLE app by adding "sys.argv.insert(1, '-Qnew')" to /Applications/IDLE.app/Contents/MacOS/IDLE. Both that and Ashwini Chaudhary's solution below seem brittle. I wonder if there is a cleaner way.
Adding the __future__ statement at the top of /usr/lib/python2.7/idlelib/PyShell.py did the job for me.
I am on Ubuntu, the path may vary for other OS:
>>> import idlelib
>>> idlelib.PyShell.__file__
'/usr/lib/python2.7/idlelib/PyShell.py'

python 2.5.4 with pyTTS 3.0 -- ValueError: "SAPI" not supported

I've been using python 2.5.4 with pyTTS 3.0 on Windows 7, using MS Speech SDK 5.1. It's been working great for well over a year. However, yesterday, two things happened almost simultaneously. MS did one of those updates that caused my system to reboot while I wasn't looking. And I ran out of disk space almost simultaneously. After clearing up some space, pyTTS no longer works. I get a "SAPI" not supported error message. From the command prompt I do the following:
>python
Python 2.5.4 (r254:67916, Dec 23 2008, 16:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyTTS
>>> x = pyTTS.Create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\Python25\Lib\site-packages\pyTTS\__init__.py", line 28, in Create
raise ValueError('"%s" not supported' % api)
ValueError: "SAPI" not supported
I have reinstalled:
python 2.5.4,
python windows extensions w32com,
pyTTS 3.0,
Microsoft Speech SDK 5.1,
Microsoft-English-TTS-51.
I have rebooted after each of these.
But it still doesn't work and I still get the same error message.
Any suggestions are much appreciated! Thanks.
The python pyTTS module simply uses the Microsoft SAPI COM objects, and if these are no longer registered the module fails in the manner you see.
Re-installing the Microsoft Speech SDK should fix this for you.
So thanks to the contributors for their suggestions. But here's what worked. pyTTS imports win32com. And win32com keeps a cache pickled in a file under Pythonxx/Lib/site-packages/win32com/gen_py/dicts.dat. Somehow, that file dicts.dat got corrupted. And somehow, when reinstalling win32com, that file didn't get blown away. Probably because it was being grabbed by python running somewhere in the background while the installation was going on. I didn't stop to investigate further. Anyway, when properly removed and win32com reinstalled, then pyTTS resumed working. --

Endless Syntax Errors for sqlite in terminal

I'm trying to lean sqlite3 and create databases, but I'm having trouble getting started. I go to the Terminal and start things off by typing sqlite3. I get the following prompt:
sqlite>
I installed sqlAcademy and am trying to work through the tutorial, but with examples like:
>>> import sqlalchemy
>>> sqlalchemy.__version__
0.7.0
They appear to be typing in the Terminal, but my code shows an error:
sqlite> import sqlalchemy;
Error: near "import": syntax error
Is there a wrapper I should be using in Terminal so I can type in Python? Do I need to individually write, compile, and run all of the example or is there an easier way?
I know this sounds vague, but I think I'm doing something very obvious wrong. Just too new to know what it is.
That's because you're running in sqlite terminal. The sample code should be run from python's terminal.
To further expand on Demian's answer:
In the terminal type:
$ python
you will get (or similar depending on which version of python you have installed)
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
From there you can enter your import sqlalchemy
Alternatively you can create a python script file (*.py) and put your code in it. Then run run the code by changing to the directory that your files are in, and entering
python filename.py
Hope that helps.

web2py Error :- unable to detect browser

i install a web2py on my machine. i simply click on web2py.exe then it asking for password then it says "unable to detect your browser".
Any help will be appreciable.
This is not an error, it is just a warning message.
This message is being introduced by this line which propose is just to open the web browser automatically.
But, even without webbrowser module you should be able to run web2py and ignore the warning message,
If you are unable to run web2py or having any trouble, please open an issue ticket and web2py developers will look in to it.
The message is coming from here:
def try_start_browser(url):
""" Try to start the default browser """
try:
import webbrowser
webbrowser.open(url)
except:
print 'warning: unable to detect your browser'
You might try the webbrowser.open from a python cli shell to see what the specific exception is. On my (OS X) system:
~ $ python
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.open('http://stackoverflow.com')
True

Categories