I'm not sure what you mean be forge, but if you mean set an arbitrary cookie manually (vs. one that was provided by the server). just use add_header() in http://docs.python.org/lib/request-objects.html
It may be possible to use CookieJar for this purpose but I've only used it for manipulating cookies set by the server... And I would agree that Python cookie APIs are less intuitive than what are available in others such as Jakarta HttpClient.... - mdf On 2/3/07, Alessandro Fachin <[EMAIL PROTECTED]> wrote: > Hi, i am trying to forge a new cookie by own with cookielib. But i don't > still have success. This a simply code: > > import cookielib, urllib, urllib2 > login = 'Ia am a cookie!' > cookiejar = cookielib.CookieJar() > urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar)) > values = {'user':login} > data = urllib.urlencode(values) > request = urllib2.Request("http://localhost/cookie.php", data) > url = urlOpener.open(request) > print url.info() > page = url.read(500000) > print page > print cookiejar > > the output of this is: > > Date: Sat, 03 Feb 2007 10:20:05 GMT > Server: Apache > X-Powered-By: PHP/5.1.6 > Set-Cookie: user=Alex+Porter; expires=Sat, 03-Feb-2007 11:20:05 GMT > Content-Length: 11 > Connection: close > Content-Type: text/html; charset=UTF-8 > > Array > ( > ) > <cookielib.CookieJar[<Cookie user=Alex+Porter for localhost.local/>]> > > And here is the code of cookie.php that i've create for this example: > > <?php > setcookie("user", "Alex Porter", time()+3600); > ?> > <?php > // Print a cookie > echo $_COOKIE["user"]; > // A way to view all cookies > print_r($_COOKIE); > ?> > > if anyone could help... Thank you > -- > http://mail.python.org/mailman/listinfo/python-list > -- Matthew Franz http://www.threatmind.net/ -- http://mail.python.org/mailman/listinfo/python-list