CGI

    Date: 06/19/05 (Web Development)    Keywords: mysql, browser, database, sql

    Hi everyone this is my first post and my first Python script.

    The script will take a URL as input. The URL will look something like this.

    thevenuslist.com/show_image.py/55.jpg

    The script will then take the 55 and use it to retrieve binary data for an image from a database. Then image headers will be sent to the browser followed by the binary information.

    I think I am having a problem with the headers. When I run the script from command line I get the headers and then a bunch of goo which is the binary information but when I run it from the browser I get an error.



    #!/usr/bin/python
    
    import MySQLdb, cgi, string, os
    
    def getScriptname():
        """ Return the scriptname part of the URL. """
        return os.environ.get('SCRIPT_NAME', '')
    
    
    def getPathinfo():
        """ Return the remainparth of the URL. """
        pathinfo = os.environ.get('PATH_INFO' '')
    
        # fix fr a well known bug in IIS/4.0
        if os.name == 'nt':
            scriptname = getScriptName()
            if string.find(pathinfo, scriptname) == 0:
                pathinfo = pathinfo[len(scriptname):]
    
    
        return pathinfo
    
    
    def getData(idNumber):
    	Con = MySQLdb.connect(host="", 
    				db="", 
    				port=3306, 
    				user="", 
    				passwd="")
    	Cursor = Con.cursor()
    
    	sql = "SELECT binary_data FROM pictures WHERE picture_id = '15'"
    	Cursor.execute(sql)
    
    #	print sql	
    #	print idNumber
    	
    	result = Cursor.fetchall()
    	Con.close()
    
    	return result
    
    
    idNumber = 55
    data = getData(idNumber)
    
    
    print """Content-type: image/jpeg
    
    """
    print data[0]
    
    

    Source: http://www.livejournal.com/community/webdev/212040.html

« Setting up a database || SOAP in Python »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home