Since dbconnect is your module file, it looks like you haven’t configured mod_wsgi to extend the Python module search path to include the directory that file is found in.
How are you configuring mod_wsgi? Graham > On 27 Apr 2016, at 9:32 AM, Jaqen Nki <[email protected]> wrote: > > Hey new issue. Wonder if you have any experience with pymysql or oracle myql > connector python for connecting python3 web app to mysql. Stuck at this part > in my course: > https://pythonprogramming.net/flask-connect-mysql-using-mysqldb-tutorial/ > Saw some wsgi errors in apache error.log so heres my post: > > How can I import a dbconnection function in PyMySQL like MySQLdb (which > works)? Ive tried this and my app is broken. : > dbconnect.py file (to be used in different parts of web app) : > > > > import pymysql > > def connection(): > conn = pymysql.connect(host = "localhost", > user = "root", > passwd = "mysqlroot", > db = "sqltest") > > c = conn.cursor() > return c, conn > > > > init.py web app file (testing the module on register page): > > > > from dbconnect import connection > > @app.route('/register/', methods=["GET","POST"]) > def register_page(): > try: > c, conn = connection() > return("okay, flask to db connection appears to be working") > except Exception as e: > return(str(e)) > > > EDIT: calling the connection() function works with MySQLdb module but not > with pymysql or mysql.connector, it just makes no sense and very frustrating. > Heres apache error log after above connection attempt (says ImportError no > module "dbconnect" yet there is and once Im in python3 shell I can import it > fine) : > > > > [Tue Apr 26 21:48:02.125650 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > mod_wsgi (pid=23265): Target WSGI script > '/var/www/site1/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., > referer: http://site1.me/ <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125714 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > mod_wsgi (pid=23265): Exception occurred processing WSGI script > '/var/www/site1/FlaskApp/flaskapp.wsgi'., referer: http://site1.me/ > <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125739 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > Traceback (most recent call last):, referer: http://site1.me/ > <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125856 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > File "/var/www/site1/FlaskApp/flaskapp.wsgi", line 6, in , referer: > http://site1.me/ <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125861 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > from FlaskApp import app as application, referer: http://site1.me/ > <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125933 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > File "/var/www/site1/FlaskApp/FlaskApp/init.py", line 2, in , referer: > http://site1.me/ <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125938 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > from dbconnect import connection, referer: http://site1.me/ <http://site1.me/> > > <http://site1.me/> > [Tue Apr 26 21:48:02.125954 2016] [wsgi:error] [pid 23265:tid > 139993628493568] [client 192.168.1.100:53645 <http://192.168.1.100:53645/>] > ImportError: No module named 'dbconnect', referer: http://site1.me/ > <http://site1.me/> > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/modwsgi > <https://groups.google.com/group/modwsgi>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/modwsgi. For more options, visit https://groups.google.com/d/optout.
