Being script1.py:
import cgi
import cgitb
print("Content-type:text/html\r\n\r\n")
print("hello")
and script2.py:
import cgi
import cgitb
import pymysql
print("Content-type:text/html\r\n\r\n")
print("hello")
In script1.py everything works fine (prints 'hello'), but script2.py returns a 500 error.
Considerations:
Then, why script2.py doesn't work?
You might consider if your script is being run by the web server (as opposed to your user shell session) in a different virtual environment, possibly one that doesn't have pymysql installed. If that's the case, you'll need to activate that virtual environment and install pymysql there.
To verify this is an instance of the library not being installed, you might try something like this in your script...
import cgi import cgitb import sys print("Content-type:text/html\r\n\r\n") print("hello") if 'pymysql' in sys.modules: print 'pymysql is installed' else: print 'pymysql is NOT installed'
Beyond this, checking your web server logs might provide more insight into why the 500 error is getting raised by the web server...