I am trying to connect with Mysql server using mentioned below python code
import mysql.connector
mydb = mysql.connector.connect(
host = "127.0.0.1",
port = 5000,
user = "user id",
password = "password"
)
print(mydb)
But while running this code to test whether I have been connected with MySQL or not, I am facing the error which I am not able to understand.
Traceback (most recent call last):
File "C:\Users\varul.jain\Desktop\Test Phase\Mysql\mydb_test.py", line 7, in <module>
password = "root"
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
self.connect(**kwargs)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
self._open_connection()
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 210, in _open_connection
self._ssl)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection.py", line 142, in _do_auth
auth_plugin=self._auth_plugin)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\protocol.py", line 102, in make_auth
auth_data, ssl_enabled)
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\protocol.py", line 58, in _auth_response
auth = get_auth_plugin(auth_plugin)(
File "C:\Users\varul.jain\AppData\Local\Programs\Python\Python36\lib\site-packages\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
Note: I have initialized the default as 5000
for the testing purpose, I have initialized the port 5000, user - root and password - root
but the authorization the default password is not available as per mentioned above error
Is there any way to check the user id and password to cross verify and update in python code accordingly?
suggestions will be helpful
Follow these steps:
You must install MySQL Server (https://dev.mysql.com/downloads/installer/)
from this install MySQL Server.
Install mysql-connector-python (in your python environment)
Use this code :
Open database connection
import mysql.connector
mydb = mysql.connector.connect(host="127.0.0.1", port="3306", user="root", password="root", auth_plugin="mysql_native_password")
print(mydb)
As per SQL documentation for python library.you need to specify the auth plugin as follows:-
conn = mysql.connector.connect(user='root', password='password', host='127.0.0.1',port=5000, database='test', auth_plugin='mysql_native_password')
print(conn)
I come across a similar problem on my centOS VPS using webmin + python3.
At first I think it might due to connection package , so I tried:
'python3 -m pip install mysql-connector' , in python it will use 'import mysql.connector'
'pip3 install PyMySQL' , in python it use 'import PyMySQL'
both dont solve the problem. Then I found there are a couples of other connection method from a website (which I dont remember its address now), which detaily explain pro and cos of each, according to it, I finally choose to use mysqlclient.
'sudo pip3 install mysqlclient' , I use this because it is more versatile and have support for python3.
All above does not solve my problem, I still face connection error.
I tried a couple of random test and accidentially with root and the skip-grant-tables option in config file, I was able to log in mysql with SSH python code, but that is not the reason , cos a normal newly created user still cannot login no matter what hosts I am accessing in the code, localhost, 127.0.0.1, domains, ....
So I revoke the skip-grant-tables option cos thats risky without protection (just for test).
Lately, from default already exist user 'root' in MySQL Server, I found it has 4 entries, so I have try to create 4 individual similar entries record in webmin -> server -> MySQL server -> User Permission.
these records have same user name and less privilege right but similar host content assigned. they are 'local' , '127.0.0.1' , 'myservername.vps.provider.ca' , '::1'
(I do not know what does the last one means)
And, Bingo, after above 4 entries added, the new user is able to log in with password authenthicate provided via python3 code.
(remember the first time, you have to set the MySQL Admin 'root' with password in MySQL Server page, so that password Login authenthication feature will work, and that password need not same as root password of system)
Thats all, this take me 6 hours. hope it can help someone using webmin as well. Please give positive vote if it helps you in anyway. thanks
How can I save the login session as a file in pyvmomi?
(ServiceInstance)
ex)
from pyVim.connect import SmartConnect
si = SmartConnect(host=self.host, user=self.user, pwd=self.pwd)
The problem I am having is that when I issue a command to the virtual machine,
Always try to connect to vSphere is likely to cause a traffic load.
So I try to save an existing session to a file and reuse it.
What should I do?
I am trying to create a job using the python api. I have created my own config, but the authentication fails. It produces an error message:
File "/usr/lib/python2.7/dist-packages/jenkins/__init__.py", line 415, in create_job
self.server + CREATE_JOB % locals(), config_xml, headers))
File "/usr/lib/python2.7/dist-packages/jenkins/__init__.py", line 236, in jenkins_open
'Possibly authentication failed [%s]' % (e.code)
jenkins.JenkinsException: Error in request.Possibly authentication failed [403]
The config file I have created was copied from another job config file as it was the easiest way to build it:
I am using the import jenkins module.
The server instance I create is using these credentials:
server = jenkins.Jenkins(jenkins_url, username = 'my_username', password = 'my_APITOKEN')
Any help will be greatly appreciated.
Error 403 is basically issued when the user is not allowed to access the resource. Are you able to access the resource manually using the same credentials? If there are some other admin credentials, then you can try using those.
Also, I am not sure but may be you can try running the python script with admin rights.
As far as I know for security reasons in Jenkins 2.x only admins are able to create jobs (to be specific - are able to send PUT requests). At least that's what I encountered using Jenkins Job Builder (also Python) and Jenkins 2.x.
I'm setting up an application on OpenShift. It requires a Python script to run every hour and extract data from an online server into a MySQL database on OpenShift. I've been filling this database for some time now by running the Python script locally on my computer and using the port-forward technique. This works like a charm. Underneath is the port-forwarding info that's displayed while doing this.
Service Local OpenShift
------- -------------- ---- -------------------
httpd 127.0.0.1:8080 => 127.12.248.131:8080
mysql 127.0.0.1:3306 => 127.12.248.130:3306
node 127.0.0.1:8081 => 127.12.248.129:8080
Press CTRL-C to terminate port forwarding
And the variables I use in my local script...
host='127.0.0.1'
user='user_placeholder'
passwd='password_placeholder'
db='3v3'
port=3306
Of course I'd like the script to run automatically on the server of OpenShift so I don't have to do so myself. After a quick search I stumbled upon the cron method. It's possible to just put a python script in a map to make it run every hour. I set up some environment variables to access my database, just like I did in the local script. However, the script can't seem to connect to the MySQL database when I tail it. I've even printed the environment variables out and they're exactly the same as the ones I used to succesfully port-forward.
host=os.environ['OPENSHIFT_EXTMYSQL_DB_HOST'] # prints '127.12.248.130'
user=os.environ['OPENSHIFT_EXTMYSQL_DB_USERNAME'] # prints 'user_placeholder'
passwd=os.environ['OPENSHIFT_EXTMYSQL_DB_PASSWORD'] # prints 'password_placeholder'
db=os.environ['OPENSHIFT_EXTMYSQL_DB_NAME'] # prints '3v3'
port=int(os.environ['OPENSHIFT_EXTMYSQL_DB_PORT']) # prints 3306
The error message:
File "/var/lib/openshift/57c57f1889f5cfd9bb00006b/app-root/runtime/repo/.openshift/cron/minutely/test.py",
line 36, in
db = MySQLdb.connect(host=os.environ['OPENSHIFT_EXTMYSQL_DB_HOST'],
user=os.environ['OPENSHIFT_EXTMYSQL_DB_USERNAME'],
passwd=os.environ['OPENSHIFT_EXTMYSQL_DB_PASSWORD'],
db=os.environ['OPENSHIFT_EXTMYSQL_DB_NAME'],
port=int(os.environ['OPENSHIFT_EXTMYSQL_DB_PORT']))
File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/__init__.py",
line 81, in Connect
return Connection(*args, **kwargs)
File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/MySQLdb/connections.py",
line 187, in init
super(Connection, self).init(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.12.248.130' (113)")
I honestly don't know where this could go wrong. I know that it's not much of a lead but if anyone thinks to know what the problem could be, I'd be glad to hear.
I am doing a project. It is using a File system(1GB File) rather than a database. I created the front end using angular. I wrote a Python-Flask-Server that handles the requests from the client( Browser) and dispatches the respective html files. However, I want to save all the users( Username and Password) regestered in a 1GB file for server side storage. Where should I start now?. Any resources ? Please help.