How to change command timeout in pywin32. 'Open' method - python

I've got the problem using pywin32 library and trying to connect to OLEDB.
Traceback
Traceback (most recent call last):
File "<input>", line 35, in <module>
File "<input>", line 31, in ado
File "<COMObject ADODB.Recordset>", line 4, in Open
the XML parser for analysis: the response Time for the XML for analysis request timed out before it was completed.', None, 0, -2147467259), None)
I've tried to add Connect Timeout=1000 to my connectionstring to no avail.
Code
import win32com.client
import pyodbc
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = CONNECTION_STRING
conn.Open(DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
strsql = u"""
select
...
...
...
"""
h = rs.Open(strsql, conn,0,1)
ts = rs.GetRows()
conn.Close()
return ts
I think that the problem is here:
h = rs.Open(strsql, conn,0,1)
I can't see which parameters should be passed to 'Open'. But I think it must have timeout parameter.
How can I change command timeout?

The problem is solved by adding:
conn.CommandTimeout=3000

Related

How to fix the error 'TypeError: can't pickle time objects'?

I am using the OpenOPC library to read data from an OPC Server, I am using 'Matrikon OPC Simulation Server', when I try to read the data it sends me the following error:
TypeError: can't pickle time objects
The code I use is the following, I run it from the python console.
CODE:
import OpenOPC
opc = OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation')
opc.read('Random.Int4')
When I run the line opc.read ('Random.Int4'), that's when the error appears.
This is how the variable appears in my MatrikonOPC Explorer:
This is the complete error:
Traceback (most recent call last):
File "C:\Python27\Lib\multiprocessing\queues.py", line 264, in _feed
send(obj)
TypeError: can't pickle time objects
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\User\PycharmProjects\OPC2\venv\lib\site-packages\OpenOPC.py", line 625, in read
return list(results)
File "C:\Users\User\PycharmProjects\OPC2\venv\lib\site-packages\OpenOPC.py", line 543, in iread
raise TimeoutError('Callback: Timeout waiting for data')
TimeoutError: Callback: Timeout waiting for data
I solved this issue by adding sync=True when calling opc.read()
CODE:
import OpenOPC
opc = OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation')
opc.read('Random.Int4', sync=True)
Reference: mkwiatkowski/openopc

OSError when reading 0x000000000000000C (Maxl DLL)

I'm trying to connect to Essbase using Maxl DLL but I'm getting an error. I think this error has to do with ctype, but I'm quite not sure how to find the root cause and fix this. Any guidance will be appreciated.
Using Maxl DLL in C:\ORACLE\Middleware\EPMSystem11R1\common\EssbaseRTC-64\11.1.2.0\bin\essmaxlu.dll
Traceback (most recent call last):
File "<ipython-input-8-c96d45911659>", line 42, in <module>
eh = esss.connect("userID", "password", "123.123.123.123")
File "C:\Python3\Lib\Essbase.py", line 220, in connect
self.sts = self.maxl.MaxLSessionCreate(c_char_p(host.encode('utf-8')), c_char_p(user.encode('utf-8')), c_char_p(password.encode('utf-8')), byref(self.ssnInit), byref(self.sid))
OSError: exception: access violation reading 0x000000000000000C
Here's what I have:
def connect(self, user, password, host='localhost'):
self.sid = c_ushort(0)
self.ssnInit = maxl_ssninit_t()
self.sts = self.maxl.MaxLSessionCreate(c_char_p(host.encode('utf-8')), c_char_p(user.encode('utf-8')), c_char_p(password.encode('utf-8')), byref(self.ssnInit), byref(self.sid))
self.user = user
self.numFlds = 0
self.bMdxQuery = 0

No access to database

I am trying to open an FDB file, but it doesn't seem to work. Whatever I try, I get this error:
Opening ./20190401_database.fdb
Traceback (most recent call last):
File "test.py", line 16, in <module>
conn = fdb.connect(dsn=local_copy, user='****', password='****', charset='iso8859_1')
File "/usr/local/lib/python3.6/site-packages/fdb/fbcore.py", line 848, in connect
"Error while connecting to database:")
fdb.fbcore.DatabaseError: ('Error while connecting to database:\n- SQLCODE: -551\n- no permission for read-write access to database /var/www/wsgi/data/20190401_database.fdb', -551, 335544352)
I am running this code as user apache, and the same user just copied the FDB file into that location, so I am pretty sure the user has read/write access.
import fdb
from datetime import date, timedelta
DB_PATH="."
yesterday = date.today() - timedelta(days = 1)
yesterday = yesterday.strftime("%Y%m%d")
filename = f'{yesterday}_database.fdb'
local_fullpath = f'{DB_PATH}/{filename}'
local_copy = local_fullpath
print("Opening "+local_copy)
conn = fdb.connect(dsn=local_copy, user='****', password='****', charset='iso8859_1')
conn.close()
Even when running the script as root, I get the same error.
The problem was in the fact that the FDB file has to be read/writable by the firebird user.
Setting that correctly made it work.

Python Connection to Hive

I installed the Hortonworks Hive ODBC driver and created a connection in the Data sources. I tested it and it worked successfully.
I installed PyODBC and wrote the following code
import os, sys, pyodbc;
con = pyodbc.connect("DSN=MyCon")
I got error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HYC00', '[HYC00] [Hortonworks][ODBC] (11470) Transactions are not supported. (11470) (SQLSetConnnectAttr(SQL_ATTR_AUTOCOMMIT))')
I also tried
import pyodbc, sys, os
pyodbc.pooling = False
pyodbc.autocommit = False
con = pyodbc.connect("DSN=MyCon")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HYC00', '[HYC00] [Hortonworks][ODBC] (11470) Transactions are not supported. (11470) (SQLSetConnnectAttr(SQL_ATTR_AUTOCOMMIT))')
also tried
con = pyodbc.connect("DSN=Tenet", autocommit=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.Error: ('HYC00', '[HYC00] [Hortonworks][ODBC] (11470) Transactions are not supported. (11470) (SQLSetConnnectAttr(SQL_ATTR_AUTOCOMMIT))')
I solved it..... I am not deleting my question and putting the answer here
pyodbc.autocommit = True
con = pyodbc.connect("DSN=MyCon", autocommit=True)
This was done based on advice of this read
https://code.google.com/p/pyodbc/issues/detail?id=162
** thanks to the advice from Kyle Porter below... it totally makes sense now **

Unable to connect to my openfire server:python

I have installed openfire server on my fedora 20 machine, and i am trying to connect and insert a new user with following..
from openfire import UserService
api = UserService("192.xxx.x.xxx:9090/", "SecretKey")
i am getting the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/python_openfire-0.2.3_beta-py2.7.egg/openfire/user_service.py", line 60, in add_user
'groups': groups_str,
File "/usr/lib/python2.7/site-packages/python_openfire-0.2.3_beta-py2.7.egg/openfire/base.py", line 34, in _submit_request
raise HTTPException(e.reason)
openfire.exception.HTTPException: unknown url type: 192.xxx.x.xxx
i have taken reference from this url:
https://github.com/plazix/python-openfire/blob/master/docs/user_service.md
any help would be appreciated!
Try prepending your URL with the protocol. Eg. HTTP:
api = UserService("http://192.xxx.x.xxx:9090/", "SecretKey")
Obviously, you also need to use a valid IP address or host name instead of "192.xxx.x.xxx".

Categories