0

I am creating python script in QGIS python console to be able to connect to mysql db and manipulate data (retrieve from db, generate shapefile and show it as a layer). I tried to install mysql connector from OSGeo4w shell: pip install mysql-connector-python but it fails with error:

C:>pip install mysql-connector-python Collecting mysql-connector-python C:\OSGEO4~1\apps\Python27\lib\site-packages\pip_vendor\requests\packages\urllib 3\util\ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the S NI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can ca use validation failures. You can upgrade to a newer version of Python to solve t his. For more information, see https://urllib3.readthedocs.io/en/latest/security .html#snimissingwarning. SNIMissingWarning C:\OSGEO4~1\apps\Python27\lib\site-packages\pip_vendor\requests\packages\urllib 3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not ava ilable. This prevents urllib3 from configuring SSL appropriately and may cause c ertain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/s ecurity.html#insecureplatformwarning. InsecurePlatformWarning Could not find a version that satisfies the requirement mysql-connector-python (from versions: ) No matching distribution found for mysql-connector-python

What is the best way to solve this?

1

1 Answer 1

0

This error occured probably to my proxy limitations. But my problem was solved by another way:

  1. pip install wheel (ussing osgeo4w command shell).

  2. download wl files from http://www.lfd.uci.edu/~gohlke/pythonlibs/

MySQL_python-1.2.5-cp27-none-win_amd64.whl mysqlclient-1.3.10-cp27-cp27m-win_amd64.whl and install them pip install MySQL_python-1.2.5-cp27-none-win_amd64.whl pip install mysqlclient-1.3.10-cp27-cp27m-win_amd64.whl

  1. see https://www.a2hosting.com/kb/developer-corner/mysql/connecting-to-mysql-using-python for the python code example to deal with db connections.

My test example is:

def doQuery( conn ) :
    cur = conn.cursor()
    cur.execute( "SELECT name, vendor FROM t" )

    for bname,bvendor in cur.fetchall() :
        print bname,bvendor

import MySQLdb
myConnection = MySQLdb.connect(host=<host_ip>, user=db_user, passwd=db_pass, db=db_schema_or_db_instance )
doQuery( myConnection )
myConnection.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.