Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How could I run this python script on my webserver?

Posted on 2011-09-28
4
Medium Priority
?
372 Views
Last Modified: 2013-12-25
I have a web server that can run python scripts, but I have no experience at all with python. I uploaded the file to my server TorBulkExitList.py and I tried calling it in the browser but it's giving me a 500 Internal Server Error. Here's the python script:

https://svn.torproject.org/svn/check/trunk/cgi-bin/TorBulkExitList.py

Is there anything I need to do before I could run this script? Any other alternative, I just need to get a list of the TOR exit IPs. I'm on a Linux/PHP/Apache server btw.
0
Comment
Question by:Bandai2
  • 4
4 Comments
 
LVL 17

Expert Comment

by:gelonida
ID: 36718068
Hm strange I thought, that I replied already, but perhaps I forgot to submit my message.


First question:
Hopw is your server configured to run python scripts?
- via CGI
- via mod_python
- via mod_wsgi

search your apache config for cgi / python/  wsgi and paste us the relevant lines.

Second question:
- does your script have execute permissions.
To be sure make chmod a+rx yourscriptname.py

Third question:
Did you ever run any python script successfully on your server.
If yoes could you show me the first few lines of the that script?


If your script is a cgi script, and you're running on linux, then make sure,
that the script starts with the line

#!/usr/bin python

The line
#!/usr/bin/env python
does normally not work for cgi scripts.



0
 
LVL 17

Expert Comment

by:gelonida
ID: 36718095
Aplogies,

I didn't look at your python script.

It seems you're using mod_wsgi

(You can recognize this as your python code just declares function and wouldn't execute anything standalone.

One can also see a function named 'application()'

This is the entrypoint of a wsgi application.
0
 
LVL 17

Expert Comment

by:gelonida
ID: 36718112
You could make a very first test with following attached wsgi 'hello world' application

Found on http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Open in new window

0
 
LVL 17

Accepted Solution

by:
gelonida earned 2000 total points
ID: 36718178
Look at your apache config file

You had to add an entry of the kind

WSGIScriptAlias /TorBulkExitList /usr/local/www/mypath/TorBulkExitList.py

You should not put wsgi python scripts in a /cgi-bin url

CGI and WSGI are two incompatible ways of embedding python in a web server
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question