I'm trying to connect to mySQL using mysql-connector and I'm getting an error:
runfile('C:/Users/Idan/Desktop/תכנות/ניסויים/idk/adding_test/connect_to_db.py', >wdir='C:/Users/Idan/Desktop/תכנות/ניסויים/idk/adding_test')
Traceback (most recent call last):
File "C:\Users\Idan\Desktop\תכנות\ניסויים\idk\adding_test\connect_to_db.py", >line 13, in
database = 'temp'
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector_init_.py", >line 271, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 95, in init
self._in_transaction = False
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector\abstracts.py", >line 985, in connect
self._open_connection()
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 205, in _open_connection
ssl_options.get('verify_identity') or
File "C:\Users\Idan\anaconda3\lib\site->packages\mysql\connector\connection.py", line 193, in _get_connection
if client_flags & ClientFlag.SSL:
File "C:\Users\Idan\anaconda3\lib\site-packages\mysql\connector\network.py", >line 565, in init
super(MySQLTCPSocket, self).init()
TypeError: super(type, obj): obj must be an instance or subtype of type
I have tried searching online and I can't find problem with my code (and yes the password is correct):
import mysql.connector as mysql
db = mysql.connect(
host = 'localhost',
user = 'root',
password = '10iDun7lEvy3',
database = 'temp'
)
c = db.cursor()
Related
I was trying to connect the mysql with python.
import mysql.connector
db = mysql.connector.connect()
Uptill this point everything was fine. But after this when I started specifying the attributes of the connect command, using the code bellow
import mysql.connector
db = mysql.connector.connect(
host = "localhost", #specifies the host computer(in this case this computer only)
user = "root", #specifies the user
passwd = "<my password was here>"
)
this error came up on running the code,
Traceback (most recent call last):
File "C:/Users/Co-valent Cyclist/Desktop/Python + MySQL/test 1.py", line 6, in <module>
passwd = "co_valent_bonds"
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\__init__.py", line 177, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 104, in __init__
self.connect(**kwargs)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 785, in connect
self._post_connection()
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 757, in _post_connection
self.set_charset_collation(self._charset_id)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in set_charset_collation
charset_name, collation_name))
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 970, in _execute_query
self.cmd_query(query)
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 590, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\Co-valent Cyclist\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\connection.py", line 478, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1115 (42000): Unknown character set: 'utf8mb4'
how do I rectify this? Please help me out. Thanks!!
Use charset="utf8" while creating the connection object .
If your characters actually use the superset utf8mb4 then this may cause problems, but if not, then this should work!
import mysql.connector
db = mysql.connector.connect(
host = "localhost", #specifies the host computer(in this case this computer only)
user = "root", #specifies the user
passwd = "<my password was here>",
charset = "utf8"
)
After adding
db = DAL('mysql://admin:admin#localhost/web2py')
I got this errors..
Failure to connect, tried 5 times: Traceback (most recent call last): File "C:\Projects\web2py\gluon\packages\dal\pydal\base.py", line 457, in init self._adapter = adapter(**kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters__init__.py", line 39, in call obj = super(AdapterMeta, cls).call(*args, **kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\base.py", line 369, in init super(SQLAdapter, self).init(*args, **kwargs) File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\base.py", line 53, in init self.reconnect() File "C:\Projects\web2py\gluon\packages\dal\pydal\connection.py", line 154, in reconnect self.connection = self.connector() File "C:\Projects\web2py\gluon\packages\dal\pydal\adapters\mysql.py", line 51, in connector return self.driver.connect(**self.driver_args) File "MySQLdb/init.py", line 81, in Connect File "MySQLdb/connections.py", line 193, in init TypeError: 'password' is an invalid keyword argument for this function
I have installed mysql, mysql-connector for python, mysql-client, python2.7 and so on
db = DAL('mysql://admin:admin#localhost/web2py')
I expecting this will be connect but not 😒😒😒
Try something like this
uri = mysql://user:password#host/databasename
And also, use Python 3 goodluck :)))
I am trying to connect python to mysql by this code--
(I am using the mysql.connect library)
import mysql.connector
cnx = mysql.connector.connect(user='root',
password='password',
host='127.0.0.1',
database='db')
print(cnx)
cnx.close()
But it continues to throw the error--
Traceback (most recent call last):
File "D:/ted/main.py", line 5, in <module>
database='db')
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\__init__.py",
line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py",
line 94, in __init__
self.connect(**kwargs)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\abstracts.py",
line 722, in connect
self._open_connection()
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py",
line 211, in _open_connection
self._ssl)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\connection.py",
line 141, in _do_auth
auth_plugin=self._auth_plugin)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\protocol.py",
line 102, in make_auth
auth_data, ssl_enabled)
File "C:\Program Files (x86)\Python36-32\lib\mysql\connector\protocol.py",
line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "C:\Program Files (x86)\Python36-
32\lib\mysql\connector\authentication.py", line 191, in get_auth_plugin
"Authentication plugin '{0}' is not supported".format(plugin_name))
mysql.connector.errors.NotSupportedError: Authentication plugin
'caching_sha2_password' is not supported
Process finished with exit code 1
I have started the mysql sever in workbench and the also checked the status.
Also database named "db" is also there
Also checked if the host is proper.
-->Removed ssl also.
It seems that your MySQL Server version is 8.x and in that case the default MySQL connector is caching_sha2_password. In the other hand your error is maybe because your python client connector does not support this Authentication Plugin and you should explicitly change the Authentication Plugin to the old one (mysql_native_password).
cnx = mysql.connector.connect(user='root', password='password',
host='127.0.0.1', database='db',
auth_plugin='mysql_native_password')
I am trying to retrieve values from db and I am stack from start because sqlite3 is unable to open the db file after I was giving the right path.
Version 1:
sqlite_file = os.environ.get('DATABASE_URL', 'sqlite:///db.sqlite')
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
Version 2:
sqlite_file = app.config['SQLALCHEMY_DATABASE_URI']
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
Where:
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', 'sqlite:///db.sqlite')
In both situations the error is
Error on request:
Traceback (most recent call last):
File "/home/ubuntu/workspace/avb/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 209, in run_wsgi
execute(self.server.app)
File "/home/ubuntu/workspace/avb/venv/lib/python3.6/site-packages/werkzeug/serving.py", line 197, in execute
application_iter = app(environ, start_response)
File "/home/ubuntu/workspace/avb/venv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/ubuntu/workspace/avb/app.py", line 222, in <module>
conn = sqlite3.connect(sqlite_file)
sqlite3.OperationalError: unable to open database file
For sqlite3.connect() start out using the actual filename (e.g. example.db) as the argument.
Same for environ.get(): use the actual filename, not the sqlite:/// address.
I have a system running on Google App Engine in Python with web2py.
Before it was connected with a Google Cloud SQL database.
Now I need it to connect to a database at DreamHost.
db = DAL ('mysql: // User: senha#mysql-apollo-apollo.apollosolucoes.com/bancodedados' driver_args = {
}, Migrate_enabled = False, lazy_tables = True)
This generating me this error:
Traceback (most recent call last): File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/restricted.py",
line 220, in restricted
exec ccode in environment File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/applications/frontend/models/b_db.py",
line 12, in
}, Migrate_enabled = False, lazy_tables = True) File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 7867, in init
raise RuntimeError ("Failure to connect, tried% d times: \ n% s"% (attempts, tb)) RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last): File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 7845, in init
self._adapter = ADAPTERS [self._dbname] (** kwargs) File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 688, in call
obj = super (AdapterMeta, cls) .__ call __ (* args, ** kwargs) File
"/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py"
line in 2728, in init
if do_connect: self.reconnect () File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py",
line 648, in reconnect
self.connection = f () File "/base/data/home/apps/s~apollo-solutionworkshop/teste2.386857474473035619/gluon/dal.py"
line in 2726, in connector
self.driver.connect return (** driver_args) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/init.py",
line 81, in Connect
return Connection (* args, ** kwargs) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/MySQLdb-1.2.4b4/MySQLdb/connections.py",
line 190, in init
super (Connection, self) .__ init __ (* args, ** kwargs2) OperationalError: (2005, "Unknown MySQL server host
'mysql-apollo-apollo.apollosolucoes.com' (-1)")
Putting that host more User and password, and database in the program SQLyog I can connect perfectly.
When the connection was made to go to the Google Cloud SQL database went like this:
'unix_socket' '/ cloudsql / apollo-solutionworkshop: apollosystem-main'