Solved

How could I run this python script on my webserver?

Posted on 2011-09-28
4
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

636 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