I m Running Win 7 32 bit and i using python 27, i try to connect ms-access database in my QGIS plugin using pyodbc, but when i launch it i have a following error :
Traceback (most recent call last):
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 204, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\__init__.py", line 26, in classFactory
from testdbase import TestDbase
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbase.py", line 29, in
from testdbasedialog import TestDbaseDialog
File "C:/PROGRA~1/QGISDU~1/apps/qgis/./python\qgis\utils.py", line 453, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\TestDbase\testdbasedialog.py", line 28, in
r'DBQ=C:\__tmp\test1.accdb')
Error: ('HY024', "[HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023) (SQLDriverConnect); [HY024] [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023)")
And i place it like this in my code :
from PyQt4 import QtCore, QtGui
from ui_testdbase import Ui_TestDbase
import pyodbc
db = pyodbc.connect(
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};' +
r'DBQ=C:\__tmp\test1.accdb')
class TestDbaseDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_TestDbase()
self.ui.setupUi(self)
Rec_1 = self.ui.btnOke
QtCore.QObject.connect(Rec_1, QtCore.SIGNAL('clicked()'),self.Compskala)
def Compskala(self):
skal1 = self.ui.lineSkal1.text()
skal2 = self.ui.lineSkal2.text()
bandskal = ''
if skal1 == skal2:
bandskal = 'Kedua Peta dapat dipadukan'
I really a newb in this, so can someone give me a help?
Substituting backslashes for forward slashes in the filename seems to work:
Fails
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:\__tmp\test.accdb")
Traceback (most recent call last): File "", line 1, in
pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC Microsoft
Access Driver] Not a valid file name. (-1044) (SQLDriverConnect)')
Succeeds
>>> db = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};" +
"DBQ=C:/__tmp/test.accdb")
>>> connection.getinfo(pyodbc.SQL_SERVER_NAME)
'ACCESS'
Related
I am unable to achieve teradata connectivity using python. I have anaconda set up 4.3.1(64-bit) with python 2.7.13. Further i installed teradata odbc client driver for 16.20 and configured the odbc.ini file with user DSN details.
I have tried the options mentioned in this article -
https://github.com/Teradata/PyTd/issues/43
https://github.com/Teradata/PyTd/issues/89
import teradata
import os, sys
os.environ["ODBCINI"] ="/opt/teradata/client/16.20/odbc_64/odbc.ini"
os.environ["O`enter code here`DBCINST"] ="/opt/teradata/client/16.20/odbc_64/odbcinst.ini"
os.environ["LD_LIBRARY_PATH"] ="/opt/teradata/client/16.20/odbc_64/lib"
udaExec = teradata.UdaExec (appName="HelloWorld", version="1.0", odbcLibPath="/opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so")
session = udaExec.connect(method="odbc", system="tdprod", username="xxxxx", password="yyyyy")
for row in session.execute("SELECT GetQueryBand();"):
print(row)
Below is the execution log and error message of this script -
[servername#python]$ python test_teradata.py
Traceback (most recent call last):
File "test_teradata.py", line 17, in
session = udaExec.connect(method="odbc", system="tdprod", username="xxxxx", password="yyyyy")
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/udaexec.py", line 183, in connect
**args))
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 421, in __init__init(odbcLibPath)
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 367, in init initFunctionPrototypes()
File "/.../.../anaconda/lib/python2.7/site-packages/teradata/tdodbc.py", line 298, in initFunctionPrototypes prototype(odbc.SQLDrivers, SQLHANDLE, SQLUSMALLINT, PTR(SQLCHAR),
File "/.../.../anaconda/lib/python2.7/ctypes/init.py", line 375, in __getattr__func = self.getitem(name)
File "/.../.../anaconda/lib/python2.7/ctypes/init.py", line 380,in __getitem__func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /opt/teradata/client/16.20/odbc_64/lib/tdataodbc_sb64.so: undefined symbol: SQLDrivers
If supplied, the odbcLibPath should point to the ODBC Driver Manager (libodbc.so), not the ODBC Driver itself.
If the wrong driver is being selected, then add explicit driver= parameter to the connect arguments, e.g. driver="Teradata Database ODBC Driver 16.20".`
I am trying to connect python with hive data base .
Both are on different server.
hive resides on host xx.xxx.xxx.x and python is on my local system.
i am trying to use the below code , however its not working
import pyhive
from pyhive import hive
conn = hive.connect(host = 'xx.xxx.xx.xx', port = 8888, auth = 'KERBEROS', kerberos_service_name='adsuedscaihen01.aipcore.local', username ='user1', database = 'database1'
)
cur = conn.cursor()
cur.execute('SELECT * from table1')
result = cur.fetchall()
print(result)
while i run the above code , i am facing the below error:
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/pyhive/hive.py", line 64, in connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/pyhive/hive.py", line 162, in init
self._transport.open()
File "/usr/lib/python2.7/site-packages/thrift_sasl/init.py", line 79, in open
message=("Could not start SASL: %s" % self.sasl.getError()))
thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-1) SASL(-1): generic failure: GSSAPI Error: Unspecified GSS failure. Minor code may provide more information (Server not found in Kerberos database)
I am struggling to understand why I am getting this error:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandlerhandler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/a7637d5531ec9deb_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObjectobj = __import__(path[0])
File "/base/data/home/apps/g~email-report-receiver/1.407675116246966578/main.py", line 20, in <module>
from google.auth import app_engine
ImportError: No module named auth
And I am following this guide: https://developers.google.com/api-client-library/python/auth/service-accounts
(see the Google App Engine standard environment section)
Given that I am directly copying a line of code: from google.auth import app_engine from Google's guide and the code is running on an App-Engine Standard Environment, why am I getting an import error?
Here is my requirements.txt file:
google-api-python-client
google-auth
google-auth-httplib2
And my app_engine.py file:
from google.appengine.ext import vendor
vendor.add('google-auth')
vendor.add('google-auth-httplib2')
vendor.add('google-api-python-client')
Still getting the same error as above.
I m trying to understand this code which uses Py4j. However each time I run the code I'm getting the same error. I have py4j installed in my Ubuntu 14.04. The jar file is in usr/share/py4j.
The code is
from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktParameters
from nltk.tokenize import wordpunct_tokenize , sent_tokenize
from py4j.java_gateway import JavaGateway
import nltk
from nltk.tree import Tree
import os.path
import parsers
LangPaths =os.path.realpath("/home/Downloads/Abstractive Summarizer/SumMe-master/Summarizer/langdetector/profiles/")
tltagger = nltk.data.load("taggers/english.pickle")
tlChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_binary.pickle")
enChunker = nltk.data.load("chunkers/maxent_ne_chunker/english_ace_multiclass.pickle")
punkt_param = PunktParameters() #creates an opening for tokenizer parameters.
punkt_param.abbrev_types = set(['gng','mr','mrs','dr','rep']) #abbreviations further accepted goes here
sentence_splitter = PunktSentenceTokenizer(punkt_param)
tokenized = ""
gateway = JavaGateway()
detector = gateway.entry_point
detector.init(LangPaths)
The error which I m getting is
File "/home/shiju/Downloads/Abstractive
Summarizer/SumMe-master/Summarizer/preprocessor.py", line 29, in
detector.init(LangPaths)
File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
line 811, in __call_ answer =
self.gateway_client.send_command(command)`
File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
line 624, in send_command
connection = self._get_connection()
File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
line 579, in _get_connection
connection = self._create_connection() File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py", line
585, in _create_connection
connection.start()
File "/usr/local/lib/python2.7/dist-packages/py4j/java_gateway.py",
line 697, in start
raise Py4JNetworkError(msg, e) py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server
I think Python is unable to connect with the Java application
I am currently using the following versions
Python - 2.7.10 ( 32 bit , win)
AndroidViewClient - androidviewclient-10.7.1-py2.7.egg
I have a simple program as below
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
device, serialno = ViewClient.connectToDeviceOrExit()
vc = ViewClient(device=device, serialno=serialno)
device.takeSnapshot().save('Menu.png','PNG')
This is giving me the following error
*Traceback (most recent call last):
File "dump.py", line 14, in <module>
device.takeSnapshot().save('Menu.png','PNG')
File "C:\Python27\lib\site-packages\androidviewclient-10.7.1-py2.7.egg\com\dtmilano\android\adb\adbclient.py", line 678, in takeSnapshot
image = Image.open(stream)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2126, in open
% (filename if filename else fp))
IOError: cannot identify image file <cStringIO.StringI object at 0x023462A8>*
The Same snippet code - works for some devices and for some it doesnt
How can i figure out what is wrong with the devices where it doesnt work
Also please help me idetify any configuration issues as i am new to this