Raf, all I can say is, Egads! The documentation certainly is not clear! I have used Python for years and this simple Stack Overflow question that I thought I'd quickly nab before getting started on real work for the day has taken me more than twenty minutes to answer. :-)
First: it turns out that the "Cookie" library and the "cookielib" library are completely separate and have nothing to do with each other. This is stated in the documentation, but you have to scroll down to the "See Also" section of each documentation page to find this out. It would be helpful if this were at the top of each page instead.
So, when you pass an object from the "Cookie" library into "cookielib", you're confusing the "cookielib" internals because it stores cookies inside of dictionaries and a "Cookie" cookie looks like — guess what! — a dictionary, so "cookielib" confuses it for one of its own internal data structures and saves other cookies inside of it. The error I get as a result is:
<type 'exceptions.AttributeError'>: 'str' object has no attribute 'discard'
args = ("'str' object has no attribute 'discard'",)
message = "'str' object has no attribute 'discard'"
Actually, that's the error I get after sticking a bunch of attributes on the Cookie.Cookie object that don't belong there, but that I added before I realized that I was engaged in the hopeless task of trying to get a Cookie.Cookie to behave like a cookielib.Cookie. :-) The earlier errors were all attribute-missing errors like:
<class 'Cookie.CookieError'>: Invalid Attribute name
args = ('Invalid Attribute name',)
message = 'Invalid Attribute name'
(And I'm putting the errors here in case some poor future soul mixes up the Cookie classes and does the Google searches I just did, none of which turned up any results for the errors I was getting!)
So before we proceed farther, I have to know: are you trying to act like a web server, delivering cookies to clients and trying to get them back intact when the client sends their next request, in which case I should show you how the "Cookie" module works? Or are you writing a web client, for testing or for fun, that messes with the cookies that it sends with a web request to a web site, in which case we should talk about "cookielib"?