Unable to connect to Remote Oracle Database using Python script - python

I am unable to connect to the remote Oracle DB using python script. I am writing the below code to my script, and facing the error as below:
I have checked the following checkpoints as below:
1. Version of Python and Oracle client is same i.e. 64 bit
2. cx_Oracle module installation
3. I have downloaded ODPI-C but I don't know what to do with it.
I am using MAC OSX.
Code:
import sys
import cx_Oracle
dsn_tns=cx_Oracle.makedsn('dbpx87mp.co.zing.com','1901','bpx87mp')
conn=cx_Oracle.connect('admin','Password',dsn_tns)
cur=conn.cursor()
cur.execute("select * from <table_name>")
for line in cur:
print(line)
cur.close()
conn.close()
Error:
Traceback (most recent call last):
File "/Users/558220/Library/Preferences/PyCharmCE2019.2/scratches/oraScript.py", line 6, in <module>
conn=cx_Oracle.connect('admin','Password',dsn_tns)
cx_Oracle.DatabaseError: DPI-1047: Cannot locate a 64-bit Oracle Client library: "dlopen(libclntsh.dylib, 1): image not found". See https://oracle.github.io/odpi/doc/installation.html#macos for help

On macOS, you can't use the default system Python with cx_Oracle because this Python has restricted entitlements and will fail to load Oracle client libraries.
Use Python via something like homebrew or install Python yourself. See the cx_Oracle installation instructions https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#installing-cx-oracle-on-macos

Related

Use python 3 to connect to hive

i am trying to access hive using python 3.7
i am using pyhive to do it
when i try to use pyhive in python 3.7 i am getting the following error
from pyhive import hive
Traceback (most recent call last):
File "code_sample.py", line 2, in <module>
import pyhive.hive
File "/usr/local/lib/python3.7/site-packages/pyhive/hive.py", line 337
def execute(self, operation, parameters=None, async=False):
^
SyntaxError: invalid syntax
but when i do the same in python 2.6 version i am not facing any errors
can you please help me with this, if its not possible with pyhive can you suggest some better options to connect to hive with python 3.6 or 3.7
From python 3.7, async is a keyword and variables cant be named async. So pyhive package needs to be fixed, to work with python3.7
This should work fine with python 3.6, though
There was some discussion about fixing this # https://github.com/dropbox/PyHive/issues/148. You may request the developers to get it fixed.
I solved this problem by installing the following libraries.
thrift==0.11.0
thrift-sasl==0.2.1
bit-array==0.1.0
impyla==0.15.0
thriftpy==0.3.9

no module name MySQLdb

I'm doing web scraping (I'm using miniconda) and I need to import the data that I got it using scrapy to a Mysql database but when I execute my program in Python 2.7 using Scrapy it says:
no module name MySQLdb
but I've installed the connection python mysql already so I don't know what is the problem...
Connector/Python 8.0.11 Windows (x86, 64-bit), MSI Installer Python
2.7
I went to shell python and I executed >>import MySQLdb to verify if it's installed correctly and it says
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import MySQLdb
ImportError: No module named MySQLdb
I've looking for other solution and I installed a lot of other versions of this connector mysql but it doesn't work
thanks in advance.

MARIADB - Python Connection Issue

Issue - On CENTOS 7, I have installed MARIADB 10.x which is working perfectly fine, I tested with DBeaver.
to connect MARIA DB 10.x from PYTHON 2.7, I have installed "MySQL-python 1.2.5" as recommended "https://mariadb.com/blog/how-connect-python-programs-mariadb".
But getting below error while testing, Please help with this.
import mysql.connector as mariadb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
UPDATE
The lib MySQLdb1 is not maintained anymore. The MySQL company maintain a connector project.
Use MySQL Connector for Python as MariaDB database connection.
import MySQLdb as mariadb
conn = mariadb.connect(user='username', passwd='1a2b3c', db='defaultdb')
cursor = conn.cursor()
The lib mentioned on MariaDB docs is the one officialy builded by MySQL. Using this lib you will be able to follow the tutorial.
As #nizam-mohamed mentioned in comments, there is a a fork from MySQLdb1, mysqlclient.

Unable to connect MySQL and Python

I am using python 3.5 for school project, I also already installed MySQL connector for python. I tried to import the database from MySQL but it says "MySQL module not found.
import mysql.connector
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mysql.connector
ImportError: No module named 'mysql'
How do i solve this? any idea?
is mysql connector installed with python pip 3.5 ?
sometimes default pip is binded to default python, make sure you've installed it for correct version of python

mysql-connector-python-2.0.2-py3.3.msi Installation failed

I want to use "import MySQLdb"
So I downloaded Windows (Architecture Independent), MSI Installer Python 3.3
Address :http://dev.mysql.com/downloads/connector/python/
After the installation is complete,tell me installation failed
import MySQLdb
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'MySQLdb'
Please tell me how to do。thx.
PS:I use MySQL Server 5.5 and python33
Take a look at any example in the documentation and you will find that the module coming with oracle's mysql connector is not named MySQLdb, but simply mysql (or rather mysql.connector):
import mysql.connector
cnx = mysql.connector.connect(user='scott', password='tiger',
host='127.0.0.1',
database='employees')
cnx.close()
From:
http://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html

Categories

Resources