Connect to an OLAP Cube using Python on LINUX

若如初见. 提交于 2019-12-23 23:06:00

问题


I know how to connect to a MS OLAP cube using Python on Windows - well, at least one method :-).

Usually I use the win32py package and invoke a .COM object to connect:

import win32com.client
connection = win32com.client.Dispatch(r'ADODB.Connection')
connString = 'Connection String to MSOLAP CUBE'
connection.Open(connString)

However, now I want to do the same with Linux (RHEL 7.2), and I have no idea how to do that. Can you please help me with that?

What I tried so far:

I tried using pyodbc-package or the sqlalchemy to establish a connection, but was not really successful in doing so (see Edit-1 section). Moreover, I am not even sure if I am looking at the right packages, or if it is even possible at all to connect to a MS OLAP cube on Linux :S

What I found so far:

On Windows I usually use a .COM object or the .NET framework to connect to the cube. However, if I understand it right, these are Windows specific languages/frameworks, and can't be used on Linux. Right now I am looking at Mono for Linux, to see if I can use it to establish the connection.

More information:

Python version: 3.4

Linux distribution: Red Hat Enterprise Linux 7.2

sudo privileges on the machine: yes

.

Edit-1 (see: shellter comment)

I tried three different methods till now, but as mentioned above, I am not even sure if I work in the right direction. The only thing I am confident in, is that I can't establish a connection to the Cube via a .COM object (like in the Windows case), as Linux does not support the .COM environment.

Code-1:

import pyodbc
server = 'server address'
database = 'database name'
connStr = 'Provider=MSOLAP;Data Source=' + server + ';Initial Catalog=' + database + '; Application Name=Python;'
pyodbc.connect(connStr)

Error-1:

File "C:/Users/Desktop/untitled/main.py", line 35, in <module> 
File connStr(connStr)

File TypeError: 'str' object is not callable

Code-2:

import pyodbc

driver = '{MSOLAP}'
server = 'server address’
database = 'database name'
user = ‘user name’
passw = 'password'
connStr = "Provider=MSOLAP;Data Source=" + server + ";Initial Catalog=" + database + "; Application Name=Python;"

Error-2:

File "C:/Users/besechr/Desktop/untitled/main.py", line 19, in <module>
pyodbc.connect('DRIVER=' + driver + ';SERVER=' + server + ';DATABASE=' + database + ';UID=' + user + ';PWD=' + passw)

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

btw: if I try to connect to the underlying SQL server with the above-stated connection string (changing the driver parameter to {SQL Server}) it works fine.

Code-3:

import pyodbc
import sqlalchemy

engine = sqlalchemy.create_engine('mssql+pyodbc://' + server )
engine.connect()

Error-3:

sqlalchemy.exc.DBAPIError: (Error) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') None None

来源:https://stackoverflow.com/questions/38985729/connect-to-an-olap-cube-using-python-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!