在python脚本之后处理或捕获网关超时504错误

2024-06-16 14:07:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个html表单,其操作由一个python脚本处理,该脚本运行另一个向jiraapi发送请求的脚本。在我的表单中,我可以选择创建的问题的数量,当这个数量超过一定数量(比如说10个问题)时,我得到一个504网关超时错误,因为创建所有这些问题花费的时间太长。你知道吗

即使我得到了错误,我在表单中要求的所有问题都会被创建。我想抓住并处理这个错误,因为我想不出任何其他解决方案,使我的jira脚本工作更快,工作仍然完成。你知道吗

事先谢谢你的帮助。你知道吗

print "Content-Type: text/html; charset=utf-8\n\n"
print "<html><head><title>Automatisation JIRA</title>  <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css' integrity='sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T' crossorigin='anonymous'></head><body>"
import cgi, cgitb #librairie nécessaire au traitement du formulaire
cgitb.enable()

import json
import copy
import os
import sys
import subprocess
from subprocess import call

form = cgi.FieldStorage() #récupération des données du formulaire

f = open('formulaire.json',"r+")  #ouverture du fichier pivot contenant les données par défaut
formulaire=json.load(f) #récupération du format et des données par défaut dans un dictionnaire
f.close()

#A présent on modifie les données du dictionnaire avce celles provenant du formulaire
formData=['jiraChapeau', 'codeClarity','environnement','nbBundles','acces','personneAPrevenir','DNS','nomApplication']
for data in formData:
    if form.getvalue(data):
        formulaire[data]=form.getvalue(data)
nbBundles=int(formulaire['nbBundles'])
formulaire['nbBundles']= int(formulaire['nbBundles'])
for k in range(nbBundles):
    if form.getvalue("typeCouche"+str(k+1)):
        formulaire['tiers'][k]['typeCouche']=form.getvalue("typeCouche"+str(k+1))
    if form.getvalue("masterType"+str(k+1)):
        formulaire['tiers'][k]['masterType']=form.getvalue("masterType"+str(k+1))
    if form.getvalue("nVM"+str(k+1)):
        formulaire['tiers'][k]['nVM']=int(form.getvalue("nVM"+str(k+1)))
with open('formulaire.json',"w+") as fout:
    json.dump(formulaire, fout, indent=4, sort_keys=True) #on réécrit les données dans le fichier pibot
fout.close()

command = 'python automation.py formulaire.json keyword'  #commande qui sera exécuté dans l'invite de commande

p = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE)
(output, err) = p.communicate()
p_status=p.wait()

print "<p class='h3 text-succes'>Ajout du bundle avec succès</p>"
print "<hr>"
print "<a href='http://127.0.0.1:8000/projetJIRA/jirabundle.html' class='btn btn-info'>Retour au formulaire</a>"


print "</body></html>"

Tags: importform脚本jsondataeshtmlsubprocess