Subscribe/unsubscribe with CGI script?

I am running Mailman 2 (from package on Debian 6) and am trying to build my own subscription page with a Perl cgi script.
I viewed the page source of a typical subscription page to find how it normally works.
I get to the point of subscription and, using modules LWB::UserAgent and URI::Esacpe do;
my $browser = LWP::UserAgent->new;
# may need to url encode the e-mail
my $enc_email = uri_escape($email);
my $enc_name = uri_escape($fullname);
my $response = $browser->post(
"https://host.org/cgi-bin/mailman/$oper/$list",
email => $enc_email,
fullname => $enc_name,
);
if ($response->is_success) {
$resp = $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
When using real data I get the following response from Mailman
<quote> listname Subscription results
You must supply a valid email address. </quote>
and of course nothing happens.
Any ideas or criticisms are appreciated.
Best regards,
-Tom

On 05/13/2013 04:39 AM, Tom Browder wrote:
[...]
I assume $oper is 'subscribe'. There is apparently some incompatibility between the way perl supplies the post data and the way Python's cgi.FieldStorage() retrieves it as it is either not seeing the 'email' name or its value is empty. Those are the only things that produce the "You must supply a valid email address." response.
You could install the following as a CGI script somewhere and use your perl module to post to it andsee what it gets.
#!/usr/bin/python
import os import cgi import sys
def printenv(): for n,v in os.environ.items(): print '%s: %s<br>' % (n,v) print '<br>' print 'Stdin:<br>' sys.stdout.write(sys.stdin.read()) print '<br>' print 'CGI:<br>' print '%r' % cgi.FieldStorage(keep_blank_values=1)
def generateFormDocument(): print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Print Environment</TITLE></HEAD><BODY>' printenv() print ' </BODY> </HTML>'
if (__name__=='__main__'): generateFormDocument()
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan

On 05/13/2013 04:39 AM, Tom Browder wrote:
[...]
I assume $oper is 'subscribe'. There is apparently some incompatibility between the way perl supplies the post data and the way Python's cgi.FieldStorage() retrieves it as it is either not seeing the 'email' name or its value is empty. Those are the only things that produce the "You must supply a valid email address." response.
You could install the following as a CGI script somewhere and use your perl module to post to it andsee what it gets.
#!/usr/bin/python
import os import cgi import sys
def printenv(): for n,v in os.environ.items(): print '%s: %s<br>' % (n,v) print '<br>' print 'Stdin:<br>' sys.stdout.write(sys.stdin.read()) print '<br>' print 'CGI:<br>' print '%r' % cgi.FieldStorage(keep_blank_values=1)
def generateFormDocument(): print 'Content-type: text/html' print print '<HTML><HEAD><TITLE>Print Environment</TITLE></HEAD><BODY>' printenv() print ' </BODY> </HTML>'
if (__name__=='__main__'): generateFormDocument()
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (2)
-
Mark Sapiro
-
Tom Browder