Member Avatar for sravan953

Hey guys!

I want to make a Python script and I want to upload it online via Webs' free file hosting service. Basically, what I want to do is, when any user visits my website, the app stored on the server should immediately fire up and do some function(I haven't decided what I'll make it do!)....

So I was just wondering if it was possible....is it?

Thanks

As far as I know you'll have to set up your server for this to work. It's not going to happen client-side, for security reasons AND because the client would need Python installed AND because web-browsers don't execute python code in them. If you customize the server I'm sure you can trigger the script in the server to run, and then return results in the form of a web page which the visitor sees.

The only problem here being that a free web hosting service most likely isn't going to allow you to upload python scripts to their servers.

No they won't. I've only found one free host that let me upload Python scripts so far...

Member Avatar for sravan953

Which one shadwickman?

Zymic.com, where I have a free site hosted on their vndv.com server. I haven't tried executing Python scripts on their server, but the FTP didn't block my uploading of Python scripts when I wanted a place to back some up, whereas other free hosts wouldn't allow any .py or .pyw files.

Update:
I currently have a python cgi script running on a free web host, which I find a pretty damn good deal. It supports Python, Django, Perl, MySQL, PHP, ASP.NET, Ruby on Rails, and JSP.

I registered a co.cc domain name and just set the nameservers to the ones for my heliohost account, which they have a tutorial somewhere on how to do it if you're confused.

Member Avatar for sravan953

Also, can anyone point me to a very very basic tutorial where I can learn to make Python connect to the web and pass data?

Well if you're using it to handle form data, I'll just post a quick script.
Here's my HTML form:

<form action='cgi-bin/pycgi.py'>
        <input type='text' name='person' value='First Name' size=20>
        <input type='submit' value='Submit'>
</form>

And the script I specified as the action, "pycgi.py":

#!/usr/bin/python
import cgi

def main():
    # you need to print this line before any others!
    print "Content-type: text/html\n"

    # parse form data into dictionary
    form = cgi.FieldStorage()
    # our text field was named 'person',
    # so check to see if we have a value for it
    if form.has_key("person") and form["person"].value != "":
        print "<h1>Hello %s.</h1>" % form["person"].value
    
main()

This is a very, very simple example but as you see, you can get form data this way. You could also have Python just run calculations that you need and post them (if you can use POST, I haven't tried) so that a PHP page can use $_POST to get the values Python passed to it, and then display them, etc.

Member Avatar for leegeorg07

nice code, although i think i'll need to learn more html and python before i try something like this, at the moment im trying to make a webcrawler that uses meta tags as well as a web browser, I know i should use wxPython but i cant find any good tutorials, could anyone help me

(I know this should really be on a different thread but it just popped into my post)

Member Avatar for leegeorg07

no I never used it :(
cool thanks ill take a look

Definitely read that "VERY good tutorial" link in that post (the tut on zetcode.com) as it's very comprehensive and you'll get a good understanding of wxPython :)

Member Avatar for leegeorg07

yeah thanks, lots of people seem to like that one

By the way, you've now gotten me interested in a little side project to make a simple web browser with wxPython :P
Unfortunately, the html capabilities of the HtmlWindow in wx.html are quite poor, but I'm going to try to work on improving them possibly.

P.S. I already have my GUI done, I'm down to just the coding of the inner mechanics now :D

Member Avatar for leegeorg07

damn you! when you have finished could you send me the source code @
leegeorg07 @ hotmail.co.uk please

maybe i can take a look at that... or just say i made that :D

Hey, I'm surprised nobody mentioned ironpython. You can get python to run in the browser with ironpython under silverlight.

Member Avatar for leegeorg07

ooooh nice, but how could i use ironpython - if i did use it, to be used as a browser (just seeing if it could be done first before i add anything to my clogged up hd)

Member Avatar for leegeorg07

oh no i use xp atm and im gunna upgrade to the 7 rc before i buy 7

oh no i use xp atm and im gunna upgrade to the 7 rc before i buy 7

What does that have to do with anything?

You can just browse the SVN tree in your web browser like you would folders on your computer, and then open and view scripts/files in the browser. Or right-click and select "save link as" on them, or copy the code from the browser and save it in your text editor of choice.

Member Avatar for leegeorg07

@scru: sorry i thought you meant that if i didnt have xp it would be a problem
@shadwickman thanks, ill do it

Member Avatar for sravan953

@ shadwickman,

I am thinking of creating a HelioHost account, but what I want to know is this; if I create a program say, which prints "Hey shadwickman", how do I make the website run the script(will be uploaded) when a visitor visits my page?

Link directly to it.

ie: somesite.com/myscript.py

But make sure your print statements are "html"

ie: print "<P> Hello shadowickman </p> "

There are certain rules you have to follow for cgi scripts, they are mentioned earlier in this thread.

I definitely recommend python for web development if you have been using python for a while, and don't feel comfortable with php. It doesn't have the same kind of built in web specific stuff but it is still super powerful.

a quick word of warning though: the scripts are impossible to debug. If there is an error, nothing will show. Try and except clauses recommended.

Also, make sure your permissions are set correctly.

Member Avatar for sravan953

Thanks a lot zachabesh! Cool!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.