Jump to content

Recommended Posts

Posted

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

Guest Geoff
Posted

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

Posted
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) .

Guest Geoff
Posted

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?

Posted
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

Guest Geoff
Posted

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

Posted

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.

Guest Geoff
Posted
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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...