Jump to content

MySQLdb in Python gives error


arjun024

Recommended Posts

The features page of MySQL says that the MySQLdb python library is enabled. But, my python code gives a 500 Internal Server Error when using it. I commented out the MySQLdb section and made sure that the problem is with MySQLdb - the "import MySQLdb" itself causes the error. Is the library no more available here? Is there any other method i can access the database from the code ? Everything else is wonderful. Thanks

Link to comment
Share on other sites

What version of python are you using and what server are you on?

 

I am on Stevie. i am using the WSGI mode.

The python features page (http://www.heliohost.org/home/features/languages/python) tells me that the python version is Python 2.4.3..

i am using the shebang line "#!/usr/bin/env python"

 

The code i used is exactly like the snippet given in the python libraries section of the MySQL features page (http://www.heliohost.org/home/features/databases/mysql) .

Link to comment
Share on other sites

Guest Geoff

Are you using a django application?

 

Actually we have several versions of python installed:

 

python 2.4

python 2.7

python 3.2

 

WSGI uses python 2.7.

 

What are the contents of your dispatch.wsgi file?

Link to comment
Share on other sites

Are you using a django application?

 

Actually we have several versions of python installed:

 

python 2.4

python 2.7

python 3.2

 

WSGI uses python 2.7.

 

What are the contents of your dispatch.wsgi file?

 

No i am not using django. well i tried the following code snippet to get the exception info:

#!/usr/bin/env python
import sys
  
def application(environ,start_response):
  try:
    import MySQLdb
    tx = 'successfully imported MySQLdb'
  except:
    tx = str(sys.exc_info())
  status = '200 OK'
  response_headers = [('Content-Type','text/html'),('Content-Length',str(len(tx)))]
  start_response(status,response_headers)
  return [tx]

 

it gave me the following:

(, ExtractionError("Can't extract file(s) to egg cache\n\nThe following error occurred while trying to extract file(s) to the Python egg\ncache:\n\n [Errno 13] Permission denied: '//.python-eggs/MySQL_python-1.2.3-py2.7-linux-x86_64.egg-tmp'\n\nThe Python egg cache directory is currently set to:\n\n //.python-eggs\n\nPerhaps your account does not have write access to this directory? You can\nchange the cache directory by setting the PYTHON_EGG_CACHE environment\nvariable to point to an accessible directory.\n",), )

 

Plus, how do i set which python version to use, in my code. Thanks

Link to comment
Share on other sites

Guest Geoff

You didn't follow the instructions on http://www.heliohost.org/home/features/languages/python

 

Your dispatch.wsgi should be like this:

 

import os, sys
sys.path.append("/home/your_cpanel_username/public_html/project_subdirectory");
os.environ['PYTHON_EGG_CACHE'] = '/home/your_cpanel_username/.python_egg_cache'
def application(environ,start_response):
  try:
    import MySQLdb
    tx = 'successfully imported MySQLdb'
  except:
    tx = str(sys.exc_info())
  status = '200 OK'
  response_headers = [('Content-Type','text/html'),('Content-Length',str(len(tx)))]
  start_response(status,response_headers)
  return [tx]

 

And then you should have created /home/your_cpanel_username/.python_egg_cache and chmoded it to 777.

 

Plus, how do i set which python version to use, in my code. Thanks

 

You can't change the version if you are using WSGI/django, you are stuck with 2.7.

 

However, if you are using CGI, you can change the version with the shebang:

 

#!/usr/bin/env python for python 2.4

#!/usr/bin/env python2.7 for python 2.7

#!/usr/bin/env python3.2 for python 3.2

Link to comment
Share on other sites

SOLVED

the issue was actually this :

my home dir wasn't

/home/your_cpanel_username/

 

it was:

/home1/your_cpanel_username/

 

Thanks a lot Geoff.

if new users are given this home1 dir i suggest you make changes to your features/languages/python page

 

Thanks again.

Link to comment
Share on other sites

Guest Geoff
if new users are given this home1 dir i suggest you make changes to your features/languages/python page

 

New users are given the /home1 directory because /home filled up. However, most users still have the /home directory.

 

Glad your problem got solved.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...