Re: Mimetools and how to use it

2001-11-14 Thread Skip Montanaro


Ladislav> From a web server I receive headers that is an instance of the
Ladislav> class MIMETOOLS.MESSAGE.  How can decode it ...

You need to call one of its header retrieval methods (there are several to
choose from).  For more detail, check the mimetools library reference page:

http://www.python.org/doc/current/lib/module-mimetools.html

and the libref page of rfc822, its base class:

http://www.python.org/doc/current/lib/module-rfc822.html

Ladislav> and how to extract cookies then?

Assuming your mimetools.Message instance is referenced by the name "msg",
you'd retrieve the Set-Cookie headers with something like:

cookies = msg.getallmatchigheaders("Set-Cookie")

Note that you may need to put the actual headers back together.  This method
returns the raw lines, including continuation lines, as separate list
elements. 

-- 
Skip Montanaro ([EMAIL PROTECTED])
http://www.mojam.com/
http://www.musi-cal.com/
___
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython



Re: HTTPLib and POST problem with '?'

2002-01-14 Thread Skip Montanaro


Ladislav> If I use example from Python doc like this
Ladislav> 
Ladislav> import httplib, urllib
Ladislav>  params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
Ladislav>  h = httplib.HTTP("www.musi-cal.com:80")
Ladislav>  h.putrequest("POST", "/cgi-bin/script.cgi")
...
Ladislav> 
Ladislav> it works well but only if the script is like
Ladislav> http://www.musi-cal.com/cgi-bin/script.cgi
Ladislav> but if the script is like
Ladislav> http://www.musi-cal.com/cgi-bin/script.cgi?name=Paul
Ladislav> (note a part after ? ) it means that PUTREQUEST should be
Ladislav>  h.putrequest("POST", "/cgi-bin/script.cgi?name=Paul")

Ladislav> but httplib ignores everything after '?' and sends only
Ladislav> /cgi-bin/script.cgi
Ladislav>   again

You can change things a couple ways:

* If you want to use the POST method, you must always send the
  parameters using a call to the send() method of the HTTP object.  In
  this case, you had

params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
...
h.send(params)

  If you want the parameter to be "name" with a value of "Paul", change
  the call that sets params to

params = urllib.urlencode({'name': 'Paul'})

* Use the GET method instead of the POST method:

h = httplib.HTTP("www.musi-cal.com:80")
h.putrequest("GET", "/cgi-bin/script.cgi?name=Paul")
h.putheader('Accept', 'text/plain')
h.putheader('Host', 'www.musi-cal.com')
h.endheaders()
reply, msg, hdrs = h.getreply()

In any case, make sure when you test your code you are communicating with a
web server that you know and that actually has the URL you are interested
in.  As the webmaster of www.musi-cal.com I can tell you with a fair degree
of certainty there is no CGI script here named "script.cgi".

-- 
Skip Montanaro ([EMAIL PROTECTED] - http://www.mojam.com/)
___
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython