FAQ
Hi;
I have this code:

#!/usr/bin/python

import datetime, Cookie, random
import time, string
import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())

def index():
form = cgi.FieldStorage()
referrer = form.getfirst('referrer', '')
expiration = datetime.datetime.now() + datetime.timedelta(days0)
cExpires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S EST")
cPath = '/' # could be specific folder in site
cComment = '%s' % referrer
cDomain = ''
cMaxAge = 30 * 24 * 60 * 60
cVersion = 1
print "Content-Type: text/html"
print
print '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
'''
ourTime = str(time.time())
cookie = os.environ.get('HTTP_COOKIE')
if not cookie:
cookie = string.replace(ourTime, '.', '')
cookie = Cookie.SimpleCookie()
cookie['lastvisit'] = ourTime
cookie['lastvisit']['expires'] = cExpires
cookie['lastvisit']['path'] = cPath
cookie['lastvisit']['comment'] = cComment
cookie['lastvisit']['domain'] = cDomain
cookie['lastvisit']['max-age'] = cMaxAge
cookie['lastvisit']['version'] = cVersion
else:
cookie = Cookie.SimpleCookie(cookie)
cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1],
'.', '')
cookie = cookie[:-1]
print 'Content-Type: text/html'
print
print '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Maya 2012: Transform At the Source</title>
<SCRIPT language="JavaScript">
<!--
'''
print 'window.location="preloader.py?referrer=%s&width=" + screen.width;'
% referrer
print '''
//-->
</SCRIPT>
'''
cookie.load(cookie)
print '</head>\n<body bgcolor="#000000">\n</body>\n</html>'

index()


The problem is that it prints "Content-Type: text/html" to the screen for a
split-second on a white background (despite the fact that I explicitly
declare the bgcolor as black). I don't want the visitor to see that. If
necessary, make the bgcolor black so they don't see it. What do?
TIA,
Beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110309/e55e2439/attachment.html>

Search Discussions

  • Ian at Mar 9, 2011 at 9:33 pm

    On 09/03/2011 21:01, Victor Subervi wrote:
    The problem is that it prints "Content-Type: text/html" to the screen
    If you can see what is intended to be a header, then it follows that you
    are not sending the header correctly.

    Sorry - can't tell you how to send a header. You don't say what
    framework you are using.

    Ian
  • Victor Subervi at Mar 10, 2011 at 11:48 pm

    On Wed, Mar 9, 2011 at 5:33 PM, Ian wrote:
    On 09/03/2011 21:01, Victor Subervi wrote:

    The problem is that it prints "Content-Type: text/html" to the screen
    If you can see what is intended to be a header, then it follows that you
    are not sending the header correctly.

    Sorry - can't tell you how to send a header. You don't say what framework
    you are using.
    Framework? Python on CentOS, if that's what you're asking. From what I know
    of python, one always begins a web page with something like this:

    print "Content-Type: text/html"
    print
    print '''
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>

    and this has worked in the past, so I'm surprised it doesn't work here.
    Don't understand what I've done wrong, nor why it prints the first line to
    screen.
    TIA,
    Beno
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110310/45adc6bb/attachment.html>
  • Benjamin Kaplan at Mar 11, 2011 at 12:50 am

    On Thu, Mar 10, 2011 at 6:48 PM, Victor Subervi wrote:
    On Wed, Mar 9, 2011 at 5:33 PM, Ian wrote:
    On 09/03/2011 21:01, Victor Subervi wrote:

    The problem is that it prints "Content-Type: text/html" to the screen
    If you can see what is intended to be a header, then it follows that you
    are not sending the header correctly.

    Sorry - can't tell you how to send a header. You don't say what framework
    you are using.
    Framework? Python on CentOS, if that's what you're asking. From what I know
    of python, one always begins a web page with something like this:

    ? print "Content-Type: text/html"
    ? print
    ? print '''
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>

    and this has worked in the past, so I'm surprised it doesn't work here.
    Don't understand what I've done wrong, nor why it prints the first line to
    screen.
    TIA,
    Beno
    Typically, people developing web applications use a framework such as
    Django or TurboGears (or web.py or CherryPy or any of a dozen others)
    rather than just having the CGI scripts print stuff out. Rather than
    having your Python script just print out a page, you make a template
    and then have a templating engine fill in the blanks with the values
    you provide. They'll also protect you from things like Injection
    attacks and cross-site scripting (if you don't know what those are,
    you're probably vulnerable to them).
  • Victor Subervi at Mar 11, 2011 at 1:19 am

    On Thu, Mar 10, 2011 at 8:50 PM, Benjamin Kaplan wrote:
    print "Content-Type: text/html"
    print
    print '''
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>

    and this has worked in the past, so I'm surprised it doesn't work here.
    Don't understand what I've done wrong, nor why it prints the first line to
    screen.
    TIA,
    Beno
    Typically, people developing web applications use a framework such as
    Django or TurboGears (or web.py or CherryPy or any of a dozen others)
    rather than just having the CGI scripts print stuff out. Rather than
    having your Python script just print out a page, you make a template
    and then have a templating engine fill in the blanks with the values
    you provide. They'll also protect you from things like Injection
    attacks and cross-site scripting (if you don't know what those are,
    you're probably vulnerable to them).

    ok. I'm looking into Django. I'm ok for injections and I think most of my
    data is sanitized. Now, can someone please address my question? See above.
    TIA,
    Beno
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110310/8bb2ca2b/attachment.html>
  • Alex23 at Mar 11, 2011 at 2:00 am

    Benjamin Kaplan wrote:
    Typically, people developing web applications use a framework such as
    Django or TurboGears (or web.py or CherryPy or any of a dozen others)
    rather than just having the CGI scripts print stuff out.
    You're fighting an uphill battle with that suggestion, it's been made
    many, _many_ times before:

    Tim Chase wrote:
    4) Don't be afraid to reuse existing technologies: could installing
    osCommerce on a $3/month web-server and tweaking the PHP code have sufficed
    for what you need? Could you have used Django+Satchmo to get yourself up
    and running with proven code, tweaking what you need? I remember you
    dismissing the suggestion to use existing web-frameworks.
    Victor Subervi wrote:
    <sigh>
    Bringing that up again, are you? I was all but done with the shopping cart
    when you suggested I re-invent the wheel based on another technology. Yeah,
    sure, throw out 10,000 lines of the 12,000 line program so I can rebuild on
    a new technology. Brilliant, that. Thanks for the suggestion. Now, can we
    get back to my question?
    </sigh>
    Once again: Victor Subervi has been crowd sourcing code for paid
    projects on this list for 2-3 years now. He's made it very clear he
    doesn't care about good practices, as anyone who ever engaged in the
    pointless debate to get him to use bound parameters in his SQL
    statements will recall.

    He's comp.lang.python's version of Sisyphus. Or maybe Sisyphus'
    boulder...I forget where I was going with this.
  • Victor Subervi at Mar 11, 2011 at 5:42 pm

    On Fri, Mar 11, 2011 at 4:26 AM, Dennis Lee Bieber wrote:

    On Thu, 10 Mar 2011 18:00:10 -0800 (PST), alex23 <wuwei23 at gmail.com>
    declaimed the following in gmane.comp.python.general:
    He's comp.lang.python's version of Sisyphus. Or maybe Sisyphus'
    boulder...I forget where I was going with this.
    The boulder -- given that we are the ones suffering... <G>
    OK, fine, don't respond. The page works. I'm changing names and email
    addresses. CU as someone else.
    Bye,
    Beno
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110311/7e749d33/attachment-0001.html>
  • Ian Kelly at Mar 11, 2011 at 7:54 am

    On Wed, Mar 9, 2011 at 2:01 PM, Victor Subervi wrote:
    <title>Maya 2012: Transform At the Source</title>
    Yow. You're designing a Maya 2012 website to help some travel company
    bilk gullible people out of thousands of dollars? I would be ashamed
    to have anything to do with this.
  • Victor Subervi at Mar 11, 2011 at 5:40 pm

    On Fri, Mar 11, 2011 at 3:54 AM, Ian Kelly wrote:
    On Wed, Mar 9, 2011 at 2:01 PM, Victor Subervi wrote:
    <title>Maya 2012: Transform At the Source</title>
    Yow. You're designing a Maya 2012 website to help some travel company
    bilk gullible people out of thousands of dollars? I would be ashamed
    to have anything to do with this.
    Um...just for the record, these guys have ben featured on the FRONT PAGES
    OF:
    The Wall Street Journal
    The Los Angeles Times
    The San Francisco Chronicle
    and have appeared on:
    Eye-To-Eye with Connie Chung
    CNN's Travel Guide
    and National Geographic's Travel Magazine called them "the graddaddy of
    metaphysical tours."
    If you'll go to the "About Us" page you'll see their photo with the Dalai
    Lama.

    They're ligit :)
    Beno
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20110311/98185f4a/attachment.html>
  • Ian Kelly at Mar 11, 2011 at 9:12 pm

    On Fri, Mar 11, 2011 at 10:40 AM, Victor Subervi wrote:
    Um...just for the record, these guys have ben featured on the FRONT PAGES
    OF:
    [SNIPPED]
    I don't care if the company was founded by the second coming of Jesus
    Christ; I just call it like I see it.
    They're ligit :)
    Oh, I have no doubt that the tour is real. I'm sure that it will be
    conducted exactly as they describe it, and due to confirmation bias
    and the highly subjective nature of "global transformation", I'm even
    willing to bet that the participants will return home satisfied and
    convinced that they have taken part in some cosmically important
    historical event. The easiest people to take advantage of are the
    ones who don't even realize they've been swindled.
  • Dotan Cohen at Mar 11, 2011 at 8:22 am

    On Wed, Mar 9, 2011 at 23:01, Victor Subervi wrote:
    Hi;
    I have this code:

    #!/usr/bin/python

    import datetime, Cookie, random
    import time, string
    import cgitb; cgitb.enable()
    import cgi
    import sys,os
    sys.path.append(os.getcwd())

    def index():
    ? form = cgi.FieldStorage()
    ? referrer = form.getfirst('referrer', '')
    ? expiration = datetime.datetime.now() + datetime.timedelta(days0)
    ? cExpires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S EST")
    ? cPath = '/' # could be specific folder in site
    ? cComment = '%s' % referrer
    ? cDomain = ''
    ? cMaxAge = 30 * 24 * 60 * 60
    ? cVersion = 1
    ? print "Content-Type: text/html"
    ? print
    ? print '''
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    '''
    ? ourTime = str(time.time())
    ? cookie = os.environ.get('HTTP_COOKIE')
    ? if not cookie:
    ??? cookie = string.replace(ourTime, '.', '')
    ??? cookie = Cookie.SimpleCookie()
    ??? cookie['lastvisit'] = ourTime
    ??? cookie['lastvisit']['expires'] = cExpires
    ??? cookie['lastvisit']['path'] = cPath
    ??? cookie['lastvisit']['comment'] = cComment
    ??? cookie['lastvisit']['domain'] = cDomain
    ??? cookie['lastvisit']['max-age'] = cMaxAge
    ??? cookie['lastvisit']['version'] = cVersion
    ? else:
    ??? cookie = Cookie.SimpleCookie(cookie)
    ??? cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1],
    '.', '')
    ??? cookie = cookie[:-1]
    ? print 'Content-Type: text/html'
    ? print
    ? print '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Maya 2012: Transform At the Source</title>
    <SCRIPT language="JavaScript">
    <!--
    '''
    ? print 'window.location="preloader.py?referrer=%s&width=" + screen.width;'
    % referrer
    ? print '''
    //-->
    </SCRIPT>
    '''
    ? cookie.load(cookie)
    ? print '</head>\n<body bgcolor="#000000">\n</body>\n</html>'

    index()


    The problem is that it prints "Content-Type: text/html" to the screen for a
    split-second on a white background (despite the fact that I explicitly
    declare the bgcolor as black). I don't want the visitor to see that. If
    necessary, make the bgcolor black so they don't see it. What do?
    TIA,
    Beno
    Look at the page source in the browser. Does it begin with your
    "header" or the doctype declaration? I personally think that you need
    an additional blank line between the header and the doctype
    declaration.
  • Alex23 at Mar 14, 2011 at 4:37 am

    Ian Kelly wrote:
    Yow. ?You're designing a Maya 2012 website to help some travel company
    bilk gullible people out of thousands of dollars? ?I would be ashamed
    to have anything to do with this.
    To be fair, he _does_ appear to be bilking the company out of
    thousands of dollars by pretending to be a professional web developer,
    so maybe there's a karmic balance angle here I hadn't considered :)

    So hard to stay mad at anyone helping to immanentize the eschaton!
  • Dotan Cohen at Mar 14, 2011 at 5:07 pm

    On Wed, Mar 9, 2011 at 23:01, Victor Subervi wrote:
    Hi;
    I have this code:

    #!/usr/bin/python

    import datetime, Cookie, random
    import time, string
    import cgitb; cgitb.enable()
    import cgi
    import sys,os
    sys.path.append(os.getcwd())

    def index():
    ? form = cgi.FieldStorage()
    ? referrer = form.getfirst('referrer', '')
    ? expiration = datetime.datetime.now() + datetime.timedelta(days0)
    ? cExpires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S EST")
    ? cPath = '/' # could be specific folder in site
    ? cComment = '%s' % referrer
    ? cDomain = ''
    ? cMaxAge = 30 * 24 * 60 * 60
    ? cVersion = 1
    ? print "Content-Type: text/html"
    ? print
    ? print '''
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    '''
    ? ourTime = str(time.time())
    ? cookie = os.environ.get('HTTP_COOKIE')
    ? if not cookie:
    ??? cookie = string.replace(ourTime, '.', '')
    ??? cookie = Cookie.SimpleCookie()
    ??? cookie['lastvisit'] = ourTime
    ??? cookie['lastvisit']['expires'] = cExpires
    ??? cookie['lastvisit']['path'] = cPath
    ??? cookie['lastvisit']['comment'] = cComment
    ??? cookie['lastvisit']['domain'] = cDomain
    ??? cookie['lastvisit']['max-age'] = cMaxAge
    ??? cookie['lastvisit']['version'] = cVersion
    ? else:
    ??? cookie = Cookie.SimpleCookie(cookie)
    ??? cookie = string.replace(string.split(str(cookie['lastvisit']), '=')[1],
    '.', '')
    ??? cookie = cookie[:-1]
    ? print 'Content-Type: text/html'
    ? print
    ? print '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Maya 2012: Transform At the Source</title>
    <SCRIPT language="JavaScript">
    <!--
    '''
    ? print 'window.location="preloader.py?referrer=%s&width=" + screen.width;'
    % referrer
    ? print '''
    //-->
    </SCRIPT>
    '''
    ? cookie.load(cookie)
    ? print '</head>\n<body bgcolor="#000000">\n</body>\n</html>'

    index()


    The problem is that it prints "Content-Type: text/html" to the screen for a
    split-second on a white background (despite the fact that I explicitly
    declare the bgcolor as black). I don't want the visitor to see that. If
    necessary, make the bgcolor black so they don't see it. What do?
    TIA,
    Beno

    --
    http://mail.python.org/mailman/listinfo/python-list
    Look at the page source in the browser. Does it begin with your
    "header" or the doctype declaration? I personally think that you need
    an additional blank line between the header and the doctype
    declaration.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 9, '11 at 9:01p
activeMar 14, '11 at 5:07p
posts13
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase