I
I
ivan2016-03-28 17:01:59
Python
ivan, 2016-03-28 17:01:59

Python cgi script not working. Error 500. How to fix?

I just can't get the python test to work. It accepts values ​​from 1 to 4 from each question into a variable (value-answer option). Everything works fine at home on localhost.
test.py

#!/usr/bin/python3.4
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
import cgi
import html
import http.cookies
import os
import cgitb; cgitb.enable()
from tegi import *


form = cgi.FieldStorage()
radio1 = int(form.getfirst("radio_1","none"))
radio2 = int(form.getfirst("radio_2","none"))
radio3 = int(form.getfirst("radio_3","none"))
radio4 = int(form.getfirst("radio_4","none"))
radio5 = int(form.getfirst("radio_5","none"))
radio6 = int(form.getfirst("radio_6","none"))
radio7 = int(form.getfirst("radio_7","none"))
radio8 = int(form.getfirst("radio_8","none"))
radio9 = int(form.getfirst("radio_9","none"))
radio10 = int(form.getfirst("radio_10","none"))
n=int(form.getfirst("numer","none"))



if n==7:
    f=open('test7.txt')
    name=f.readline()
    r1=int(f.readline())
    r2=int(f.readline())
    r3=int(f.readline())
    r4=int(f.readline())
    r5=int(f.readline())
    r6=int(f.readline())
    r7=int(f.readline())
    r8=int(f.readline())
    r9=int(f.readline())
    r10=int(f.readline())
    f.close()
if n==11:
    f=open('test11.txt')
    name=f.readline()
    r1=int(f.readline())
    r2=int(f.readline())
    r3=int(f.readline())
    r4=int(f.readline())
    r5=int(f.readline())
    r6=int(f.readline())
    r7=int(f.readline())
    r8=int(f.readline())
    r9=int(f.readline())
    r10=int(f.readline())
    f.close()




print("Content-Type: text/html\n\n")

print(html1)
print("""<h1 align="center">""",name,"</h1>")


t=int('1')
if radio1== r1:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r1)
    print("<br>")
    t=int('0')

if radio2== r2:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r2)
    print("<br>")

if radio3== r3:
    print("Верно")
    print("<br>")
    t=t+1
    
else:
    print("Неверно,",r3)
    print("<br>")

if radio4== r4:
    print("Верно")
    print("<br>")
    t=t+1
    
else:
    print("Неверно,",r4)
    print("<br>")

if radio5== r5:
    print("Верно")
    print("<br>")
    t=t+1
    
else:
    print("Неверно,",r5)
    print("<br>")

if radio6== r6:
    print("Верно")
    print("<br>")
    t=t+1
    
else:
    print("Неверно,",r6)
    print("<br>")

if radio7== r7:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r7)
    print("<br>")

if radio8== r8:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r8)
    print("<br>")

if radio9== r9:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r9)
    print("<br>")

if radio10== r10:
    print("Верно")
    print("<br>")
    t=t+1

else:
    print("Неверно,",r10)
    print("<br>")
#t=t+0.5
t=int(t/2)  
print("<h1>","Оценка:",t,"</h1>")
print(html2)

test7.txt
Тест.
1
2
4
2
3
1
1
2
3
4

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2016-03-28
@VladimirAndreev

what does the error log say?

V
Vladimir Kuts, 2016-03-28
@fox_12

Try writing at the beginning of the file:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

PS And refactor the code. It can be written in an order of magnitude more compact and clearer in Python.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question