Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How could I run this python script on my webserver?

Posted on 2011-09-28
4
Medium Priority
?
369 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

722 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