4

I have some python code below that will open an exist web page if the condition occurs..

I have tried this code in IDLE , it works fine but when I call the python file in somewhere in html code unfortunately it does not display the web page which was defined in python script as email.html...

#!c:\python\python.exe
# Import modules for CGI handling 
import cgi, cgitb , json
import string
#import random
#import smtplib
import webbrowser
import threading

print ("Content-type:text/html\r\n\r\n")
# Create instance of FieldStorage 
fo = cgi.FieldStorage() 

# Get data from fields
fmail = fo.getvalue('cmail')
fpassw = fo.getvalue('cpasw')

webadrs = "http://localhost:8080/email.html"

from ConnectDB import mydb
mycursor = mydb.cursor(buffered=True)
try:
    mycursor.execute("""SELECT * FROM register WHERE ((emailh = %s ) AND ( password = %s))""",( fmail,fpassw))

    myresult = mycursor.fetchall()

    if (len(myresult) == 0):

        print("This user name or password not defined..!")
    else:
        webbrowser.open(webadrs)


except:
   # Rollback in case there is any error
   mydb.rollback()

mydb.close()



   <!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

</head>
<body>
   <form action = "/python/runwpage.py" method = "post">
Mail: <input type = "text" name='cmail'>  <br>

Password: <input type = "password" name= 'cpasw' />
<input type = "submit" value = "Submit" />
</form>

</body>
</html>

Actually, if len(myresult) == 0, I can get the first output. But when it is not equal to 0, the webbrowser function does not open the url.

Can anybody explain why? Thanks.

kiyah
  • 1,502
  • 2
  • 18
  • 27
  • you should display error catched by except or save this message in file - ie. using module logging. Maybe you get error message which can explain problem with `webbrowser.open()`. This command executes web browser on server and server may not have privilages to do it. – furas Jun 02 '19 at 22:58
  • I tried with Mac once, and it didn't work. But it worked in Windows could be something to do with permissions. – Irfanuddin Jun 02 '19 at 23:06
  • I could not run it on windows. I tried many things but no solution.. – Yangelyat Osman Jun 04 '19 at 07:36

0 Answers0