import mysql.connector as a
conn = a.connect(host="localhost",user="root",password="darshan",database="PAYSLIP")
#CREATE a database or connect to one
conn = a.connect('Tablename.db')
getting error:-
Traceback(most recent call last):
File "C:\Users\any.py", line 3, in <module>
a=mysql.connector.connect('Payslip.db')
File "C:\Users\Python\Python38-32\lib\site-packages\mysql\connector\__init__.py", line 265, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 64, in __init__
super(MySQLConnection, self).__init__(*args, **kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
Please help...
And please explain why it is not connecting in the answer...
Related
import mysql.connector
conn = mysql.connector.connect(host="localhost",
user="root",
password="mypassword",
database="mydatabase"
)
conn = mysql.connector.connect('tablename.frm')
conn.close()
When i run this program, the following error occurs:-
Traceback (most recent call last):
File "C:\Users\Real Project MYSQL.py", line 3, in <module>
conn = mysql.connector.connect('PAYSLIP.db')
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\__init__.py", line 265, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 64, in __init__
super(MySQLConnection, self).__init__(*args, **kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
>>>
#I am unable to solve this error.
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()
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 :)))
When in the Python shell I type:
import MySQLdb
Con = MySQLdb.Connect(user='testuser', password='password', db='test')
And I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "C:\Users\Nickey\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2059, <NULL>)
And no description of the error at all. Please, I am waiting for help. Thanks.
UPDATE: In case somebody will be having this problem, it appears to be connected with the new mysql_auth_plugin, with its new Strong Password Encryption for Authentication. I just switched to old_password_plugin(Legacy Authentication Method) in the configuration of MySQL Server and now [All works!].
According to the docs, password is not a keyword argument like you entered, instead it's passwd as you can see --> here
I would like to use the API to disassociate a specific VLAN from a gateway.
It can be attached with the following piece of code:
import SoftLayer
from SoftLayer.CLI import environment
env = SoftLayer.create_client_from_env()
obj = {'bypassFlag':False, 'id':None, 'networkGatewayId':65884, 'networkVlanId':944459}
res = env['Network_Gateway_Vlan'].createObject(obj)
But when I try to use method deleteObject (with same data) when the VLAN is attached of course, I get the following error:
>>> res = env['Network_Gateway_Vlan'].deleteObject(obj)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 390, in call_handler
return self(name, *args, **kwargs)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 358, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 261, in call
return self.transport(request)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/transports.py", line 215, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception): Object does not exist to execute method on. (SoftLayer_Network_Gateway_Vlan::deleteObject)
I don't understand what I missed here :(
The data seem correct since if I retry createObject I get the meaningful error below:
>>> res = env['Network_Gateway_Vlan'].createObject(obj)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 390, in call_handler
return self(name, *args, **kwargs)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 358, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/API.py", line 261, in call
return self.transport(request)
File "/Users/lochou/GitHub/ansible-dist/venv/lib/python2.7/site-packages/SoftLayer/transports.py", line 215, in __call__
raise _ex(ex.faultCode, ex.faultString)
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Public): VLAN ID 944459 is an inside VLAN for gateway gw001-par (#65884)
you need only send the id of the object that you want to delete:
e.g:
env['Network_Gateway_Vlan'].deleteObject(id=theIdofTheObject)
The create method will return you the newly created object with its id so you can do this:
res = env['Network_Gateway_Vlan'].createObject(obj)
env['Network_Gateway_Vlan'].deleteObject(id=res["id"])
I think the following piece of code does the job of retrieving the right id (different from the VLAN id) but I'm not proud of it:
vlans = env['SoftLayer_Account'].getNetworkGateways(mask="mask[insideVlans[networkVlan]]", filter={"networkGateways":{"insideVlans":{"networkVlan":{"id":{"operation":vlan_id}}}}})
if vlans:
for i in range(len(vlans[0]['insideVlans'])):
insideVlan = vlans[0]['insideVlans'][i]
if insideVlan['networkVlan']['id'] == vlan_id:
try:
res = env['Network_Gateway_Vlan'].deleteObject(id=insideVlan['id'])
except SoftLayer.exceptions.SoftLayerAPIError as e:
module.fail_json(msg=e.faultString)
There's probably something smarter though!