Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
532ced09
Commit
532ced09
authored
Oct 25, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better exception handling in cgi
parent
58b05e9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
44 deletions
+54
-44
comex_merci_pour_les_infos.py.cgi
cgi-bin/comex_merci_pour_les_infos.py.cgi
+54
-44
No files found.
cgi-bin/comex_merci_pour_les_infos.py.cgi
View file @
532ced09
...
...
@@ -10,7 +10,8 @@ __version__ = "1"
__email__
=
"romain.loth@iscpif.fr"
__status__
=
"Test"
from
cgi
import
FieldStorage
from
cgi
import
FieldStorage
from
traceback
import
format_tb
# debug
import
cgitb
...
...
@@ -21,51 +22,60 @@ if __name__ == "__main__":
# reception: the cgi library gets vars from html form within received http POST
this_data
=
FieldStorage
()
# read into local str vars
first_name
=
this_data
[
'first_name'
]
.
value
middle_name
=
this_data
[
'middle_name'
]
.
value
last_name
=
this_data
[
'last_name'
]
.
value
initials
=
this_data
[
'initials'
]
.
value
email
=
this_data
[
'email'
]
.
value
country
=
this_data
[
'country'
]
.
value
jobtitle
=
this_data
[
'hon_title'
]
.
value
keywordsss
=
this_data
[
'keywords'
]
.
value
# single string but ','-separated
# keywordzzz = this_data.getlist(keywords) # array
# fyi actual form fields were
# ['email', 'password', 'password2',
# 'hon_title', 'first_name', 'middle_name', 'last_name', 'initials',
# 'keywords', 'country', 'my-captcha', 'my-captchaHash']
# todo
# institution = this_data[].value
try
:
# read into local str vars
first_name
=
this_data
[
'first_name'
]
.
value
middle_name
=
this_data
[
'middle_name'
]
.
value
last_name
=
this_data
[
'last_name'
]
.
value
initials
=
this_data
[
'initials'
]
.
value
email
=
this_data
[
'email'
]
.
value
country
=
this_data
[
'country'
]
.
value
jobtitle
=
this_data
[
'hon_title'
]
.
value
keywordsss
=
this_data
[
'keywords'
]
.
value
# single string but ','-separated
# keywordzzz = this_data.getlist(keywords) # array
# optional
# picture = form["user_picture"]
# if picture.file & picture.filename:
# picture_bytes = picture.value
# todo
# institution = this_data[].value
# debug log
# log = open('../cgi_my_output.log', 'w')
# print('first_name:',first_name, file=log)
# print('midle_name:',midle_name, file=log)
# print('last_name:',last_name, file=log)
# print('initials:',initials, file=log)
# print('email:',email, file=log)
# print('country:',country, file=log)
# print('jobtitle:',jobtitle, file=log)
# print('keywordsss:',keywordsss, file=log)
# print('instituton:',institution, file=log)
# log.close()
# optional
# picture = form["user_picture"]
# if picture.file & picture.filename:
# picture_bytes = picture.value
# response
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
# response
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
print
(
"<TITLE>CGI script output</TITLE>"
)
print
([
k
for
k
in
this_data
])
#
print
(
'<br>first_name:'
,
first_name
)
print
(
'<br>midle_name:'
,
middle_name
)
print
(
'<br>last_name:'
,
last_name
)
print
(
'<br>initials:'
,
initials
)
print
(
'<br>email:'
,
email
)
print
(
'<br>country:'
,
country
)
print
(
'<br>jobtitle:'
,
jobtitle
)
print
(
'<br>keywords:'
,
keywordsss
)
# print('instituton:',institution)
print
(
"<TITLE>CGI script output</TITLE>"
)
print
([
k
for
k
in
this_data
])
#
print
(
'<br>first_name:'
,
first_name
)
print
(
'<br>midle_name:'
,
middle_name
)
print
(
'<br>last_name:'
,
last_name
)
print
(
'<br>initials:'
,
initials
)
print
(
'<br>email:'
,
email
)
print
(
'<br>country:'
,
country
)
print
(
'<br>jobtitle:'
,
jobtitle
)
print
(
'<br>keywords:'
,
keywordsss
)
# print('instituton:',institution)
except
KeyError
as
kerrr
:
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
print
(
"<h3>Your form was empty</h3"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<br/>"
.
join
(
format_tb
(
kerrr
.
__traceback__
)))
print
(
"</p>"
)
except
Exception
as
errr
:
print
(
"Content-type: text/html"
)
print
()
# blank line <=> end of headers
print
(
"<h3>There was an error:</h3"
)
print
(
"<p style='font-family:monospace; font-size:80
%
'"
)
print
(
"<br/>"
.
join
(
format_tb
(
errr
.
__traceback__
)))
print
(
"</p>"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment