RE: Importing MySQLdb module causes malformed header error.. plshelp!!!

Discussion in 'Python' started by Raaijmakers, Vincent (IndSys,GE Interlogix), Nov 5, 2003.

  1. Looking at your code I see some weird things...
    Is this code complete or a cut and paste version?

    1) missing the """ at the end of:
    def printContent():
    print "Content-type: text/html\n\n"
    print
    print """
    <html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en"
    lang="en">
    <head><title>Registration results</title></head>

    """????


    Also: in your person info: what is it what you want to do in < form[ "firstname" ].value >
    form[ "firstname" ] already gives you the value.

    What IDE are you using? You should already get error messages on a higher level.

    Vincent


    -----Original Message-----
    From: [mailto:]
    Sent: Wednesday, November 05, 2003 8:52 AM
    To:
    Subject: Importing MySQLdb module causes malformed header error.. pls
    help!!!


    Hello, im having this error while using Apache and the MySQLdb module.
    [error] [client 127.0.0.1] malformed header from script. Bad
    header=*** You don't have the (right): c:/program files/apache
    group/apache/cgi-bin/fig28_18.py

    I have connected all databases already. If I remove the import MySQL
    statement, theres no problem. But i need to use the database. . what
    could possibly be wrong???

    pls help.. I have the MySQLdb installed in my Python directory
    already..


    #!c:\Python23\python.exe

    import cgi
    import MySQLdb


    def printContent():
    print "Content-type: text/html\n\n"
    print
    print """
    <html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en"
    lang="en">
    <head><title>Registration results</title></head>


    def printReply():
    from convert import genPrime, genPrimeE
    p1 = genPrime()
    q1 = genPrime()
    e1 = genPrimeE()
    N1 = p1 * q1
    M1 = (p1-1)*(q1-1)
    print 'e1 %d, m1 %d' %(e1,M1)

    while(e1 % M1 == 0):
    e1 = genPrimeE()

    connection = MySQLdb.connect( db = "try" )

    cursor = connection.cursor()
    cursor.execute("insert into trials (p,q,n,m) values
    ('p1','q1','n1','m1');")
    authorList = cursor.fetchall()
    cursor.close() # close cursor
    connection.close()


    printContent()
    form = cgi.FieldStorage()

    personInfo = { 'firstName' : form[ "firstname" ].value,
    'lastName' : form[ "lastname" ].value,
    'email' : form[ "email" ].value,
    'phone' : form[ "phone" ].value,
    'book' : form[ "book" ].value,
    'os' : form[ "os" ].value,
    'message' : form["message"].value }
    printReply()


    thanks!!
    --
    http://mail.python.org/mailman/listinfo/python-list
    Raaijmakers, Vincent (IndSys,GE Interlogix), Nov 5, 2003
    #1
    1. Advertising

  2. Raaijmakers, Vincent (IndSys,GE Interlogix)

    Kiran B. Guest

    Re: Importing MySQLdb module causes malformed header error.. pls help!!!

    Hello vincent,
    im sorry... I missed some code while copying. The person info in try:
    is just for checking if the user entered all fields in the previous
    form. If not, the function printFormError() would be called. These
    values are being enterd from in a previous html form and these are the
    values i need to save in the database. Im using PythonWin to write my
    codes. im still getting the same error.

    Here is the actual code:


    #!c:\Python23\python.exe
    import cgi
    import MySQLdb

    def printContent():
    print "Content-type: text/html\r\n"
    print
    print """
    <html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en"
    lang="en">
    <head><title>Registration results</title></head>
    <SCRIPT language="JavaScript">
    <!--
    function blur()
    {
    this.form.message.blur();
    }
    //-->
    </SCRIPT>
    <body>"""

    def printReply():

    connection = MySQLdb.connect( db = "try")
    cursor = connection.cursor()

    from convert import genPrime, genPrimeE
    p1 = genPrime()
    q1 = genPrime()
    e1 = genPrimeE()
    N1 = p1 * q1
    M1 = (p1-1)*(q1-1)
    print 'e1 %d,' %e1
    print 'm1 %d' %M1

    while(e1 % M1 == 0):
    e1 = genPrimeE()
    cursor.execute("insert into trials(p,q) values ('4','546');")
    authorList = cursor.fetchall()
    cursor.close()
    connection.close()

    from convert import convertToBlocks
    list = convertToBlocks(form["message"].value)

    from convert import encryptBlock
    encList = []
    for i in list:
    x = encryptBlock(i,e1,N1)
    encList.append(x)

    nProd = 0

    for i in encList:
    nProd = (nProd + i) * 10000
    personInfo['message'] = nProd

    print """
    <form method = "post" action =
    "http://127.0.0.1/cgi-bin/whee.py" name = "fig18">

    <span style = "font-weight: bold">
    The following information has been saved in our database:
    </span><br />

    <table style = "border: 0; border-width: 0;
    border-spacing: 10">
    <tr><td style = "background-color: yellow">Name </td>
    <td style = "background-color: yellow">Email</td>
    <td style = "background-color: yellow">Phone</td>
    <td style = "background-color: yellow">OS</td>
    <td style = "background-color: yellow">Message</td></tr>
    <tr><td>%(firstName)s %(lastName)s</td><td>%(email)s</td>
    <td>%(phone)s</td><td>%(os)s</td></td><td>%(message)s</td></tr>
    </table>
    <br /><br /><br />
    <textarea rows="10" cols="50" onFocus="blur()"
    name="msg">%(message)s</textarea>
    <input type = "submit" value = "next" >
    </form></body></html>
    """ % personInfo

    def printFormError():
    print """<span style = "color: red; font-size 15pt">
    FORM ERROR</span><br />
    You have not filled in all fields.
    <span style = "color: blue"> Click the Back button,
    fill out the form and resubmit.</span><br /><br />
    Thank You."""
    printContent()
    form = cgi.FieldStorage()

    try:
    personInfo = { 'firstName' : form[ "firstname" ].value,
    'lastName' : form[ "lastname" ].value,
    'email' : form[ "email" ].value,
    'phone' : form[ "phone" ].value,
    'book' : form[ "book" ].value,
    'os' : form[ "os" ].value,
    'message' : form["message"].value }
    printReply()

    except KeyError:
    printFormError()

    Thanks!!
    Kiran B., Nov 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kiran B.

    Malformed header error... pls help!

    Kiran B., Nov 2, 2003, in forum: Python
    Replies:
    1
    Views:
    418
    Derrick 'dman' Hudson
    Nov 6, 2003
  2. Eric Wichterich

    Re: Malformed Header

    Eric Wichterich, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    392
    Eric Wichterich
    Nov 3, 2003
  3. Kiran Budhrani

    Re: Malformed Header

    Kiran Budhrani, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    425
    Kiran Budhrani
    Nov 3, 2003
  4. Kiran B.
    Replies:
    0
    Views:
    300
    Kiran B.
    Nov 5, 2003
  5. plb
    Replies:
    2
    Views:
    345
Loading...

Share This Page