Can't connect Sqlalchemy with pyodbc to SQL Server 2000 - sql

I followed this website by installing
Install:
sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc sqlalchemy
In /etc/odbcinst.ini:
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
After install I try this code and it worked, it print all records from table2
import pyodbc
conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
cursor = conn.cursor()
for row in cursor.execute('SELECT * FROM Table2'):
print (row)
However, I want to use SQLAlchemy with pyodbc and it does not work
import urllib
from sqlalchemy import create_engine
engine = create_engine('mssql+pyodbc:///?odbc_connect=' +
urllib.parse.quote_plus('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
)
for row in engine.execute('SELECT * FROM Table2'):
print (row)
ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [FreeTDS][SQL Server]'schema_name' is not a recognized function name. (195) (SQLExecDirectW)")
[SQL: SELECT schema_name()]
(Background on this error at: https://sqlalche.me/e/14/f405)
How can I connect this?

SQLAlchemy 1.4 does not support SQL Server 2000. Use pip install sqlalchemy==1.3.24.

Related

Can't connect Sqlalchemy with pymssql to SQL Server 2000 [duplicate]

I followed this website by installing
Install:
sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc sqlalchemy
In /etc/odbcinst.ini:
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
After install I try this code and it worked, it print all records from table2
import pyodbc
conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
cursor = conn.cursor()
for row in cursor.execute('SELECT * FROM Table2'):
print (row)
However, I want to use SQLAlchemy with pyodbc and it does not work
import urllib
from sqlalchemy import create_engine
engine = create_engine('mssql+pyodbc:///?odbc_connect=' +
urllib.parse.quote_plus('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
)
for row in engine.execute('SELECT * FROM Table2'):
print (row)
ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [FreeTDS][SQL Server]'schema_name' is not a recognized function name. (195) (SQLExecDirectW)")
[SQL: SELECT schema_name()]
(Background on this error at: https://sqlalche.me/e/14/f405)
How can I connect this?
SQLAlchemy 1.4 does not support SQL Server 2000. Use pip install sqlalchemy==1.3.24.

Superset - Hive Connection Issue

I can connect to HIVE using sqlalchemy without any issues :
oguz#dikanka:~$ python
Python 2.7.15+ (default, Jul 9 2019, 16:51:35)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sqlalchemy import create_engine
>>> engine = create_engine('hive://dikanka:10000')
>>> result = engine.execute("select movieid from default.ratings")
>>> result.first();
(242,)
But when I try to connect Superset to Hive, I receive the following error :
ERROR: {"error": "Connection failed!\n\nThe error message returned was:\nCan't load plugin: sqlalchemy.dialects:hive"}
Details are as follows :
I have a single-node HDP-3.1.4.0 setup on my laptop.
I have the following services up and running : HDFS 3.1.1, Hive 3.1.0, Zookeeper 3.4.6, Superset 0.23.0
Python version is Python 2.7.15+.
Hive command line interface works smoothly.
I've installed the following python modules:
pip install thrift
sudo apt-get install libsasl2-dev
pip install sasl
pip install thrift_sasl
pip install pyhive
Last but not least, I have a KUbuntu 18.04.
On Superset, I try to add a database named "default", and I set the SQLAlchemy URI to
hive://dikanka:10000
which is exactly the same URI I used with create_engine above.
Then I click "Test Connection", with all default values for the rest of the form.
I get the error as mentioned above.
In order to instal the hive sqlalchemy driver you need to do
pip install 'pyhive[hive]'
That should fix the error you got.

Google bigquery - Error message 'DataFrame' object has no attribute 'to_parquet' whereas pyarrow and fastparquet are installed

I'm trying to use the Google bigquery function load_table_from_dataframe but I get an error message stating that DataFrame object has no attribute to_parquet.
I have installed both pyarrow and fastparquet but still getting the same error message
from google.cloud import bigquery
df_test = pd.DataFrame({'Test_Name':['Charlotte','Alexis'],'Test_Age':[31,12]})
table_id = 'TEST_DF.TEST_TABLE'
job_config = bigquery.LoadJobConfig()
job = client.load_table_from_dataframe(df_test, table_id,job_config=job_config)
job.result()
I'm using Python 3.6.3 and pyarrow version 0.14.0
Any idea on what is causing the issue?
Solved with:
$ pip install --upgrade pandas

python -m pip install urllib having systax error while installation of this module

here see what happened
when I run the above command cmd I get an error while installing. As you can see in the above image.
s.connect((base64.b64decode(rip),17620)
I get syntax error: invalid token in line 191
and it is also giving me problems on some other modules also.
s.connect((base64.b64decode(rip),17620)
I get syntax error: invalid token in line 191
(I ran into this myself using jupyter notebook)
As you are using python 3 you don't need to install URL lib as it is part of core https://github.com/python/cpython/tree/3.6/Lib/urllib/
It's submodules are restructured so you need to change python 2 code like
import urllib
...
urllib.urlopen
into
import urllib.request
...
urllib.request.urlopen

How to connect to SQL Server database via adbapi (twisted.enterprise)?

All the examples I found either mysql or sqlite.
Connect base:
connect_base = adbapi.ConnectionPool("mssql", user="test", password="test", host="192.168.0.1", database="test")
I get an error:
ImportError: No module named mssql
Install pymssql
pip install pymssql
and use:
connect_base = adbapi.ConnectionPool("pymssql", user="test", password="test", host="192.168.0.1", database="test")