Question

Ajax code:

$.ajax({
    url: '../py/process.py',
    type: 'POST',
    data: {'newEpisodeXML': newEpisodeXML}
});

Python code:

#!/usr/bin/python

newEpisodeXML = self.request.get('newEpisodeXML')

testing = open('test.rss','w')
testing.write(newEpisodeXML)

I'm getting an Internal Server Error (500) and I'm on a Dreamhost VPS. I'm sure that the issue here is something simple, but the logging on Dreamhost servers is abysmal and I can't seem to figure it out.

The ajax URL is accurate. Permissions are 755.

Anyone know if Dreamhost has further requirements for .py files, or know what could be failing here?

Was it helpful?

Solution

Seems like you're trying to get Python to work like PHP, but it doesn't really do that, so you won't get magical interpretation of files.

It's been a while since I've used Dreamhost, but your best bet is probably to write your Python code and then let it run on top of Passenger. Dreamhost has some implementation details here http://wiki.dreamhost.com/Passenger_WSGI

The gist is that WSGI is a common interface between web servers and Python files so that Python files can be run upon request like you are expecting. But to get that functionality you need your Python file to implement the WSGI spec. But don't worry, it's quite easy. Just define a function named application that accepts a few ready-made parameters, and you're done.

def application(environ, start_response):
    start_response('200 OK')
    return 'Hi there!'

It's a bit more difficult to get at POST vars and other things, which is why you may want a framework to handle some of this stuff. Flask makes it very easy and has almost no overhead, but there are many different frameworks you could try.

OTHER TIPS

Are you still receiving the 500 Internal Server Error on your site? If you are, feel free to let me know which site it is and I'll have our team take a look. You can always reach out to our support team directly too via the "Contact Support" link in your DreamHost web panel. :)

Thanks,

Ellice S - DreamHost Staff

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top