[PLUG-TALK] Web server-side script in python: help needed
Aaron Burt
aaron at bavariati.org
Sat May 13 15:53:15 UTC 2017
On 2017-05-13 11:21, Rich Shepard wrote:
> A javaScript script gets the form widget contents and assigns them
> to
> variables, then passes the variable to another script that validates
> them.
> The form's action is the URL for the cgi-bin/ subdirectory on my site
> so the
> data entered on the form should (not yet tested) be collected,
> validated,
> and sent off to the server.
>
> The last step is a python script that takes the wsgi-incoming data,
> re-formats it to be smtp-acceptable, then sends the message to me. This
> is
> where I need help.
Sounds like a classic CGI script there, improved by using WSGI. I think
you're not finding much help because it's a textbook-ish problem and CGI
scripts have been supplanted by full-blown APIs.
I'm surprised that googling for "python wsgi" or "python cgi" didn't get
you a bunch of code examples.
Any decent Python book (even an outdated one) should have examples you
can lift, and the library is rich in outdated programming books.
In your place, I'd start with testing a WSGI script that just logs the
info to a file so you can verify it's working, and work separately on a
Python CLI tool that sends email. Once both work satisfactorily, mash
'em together.
You can send email from Python by shelling out to the "sendmail"
command, using an SMTP module, or sending an API request to a service
like SendGrid.
Please be very careful about sanitizing input so someone doesn't try
inserting cc: or to: headers and using you for a mail relay.
Regards,
Aaron
More information about the PLUG-talk
mailing list