{"id":332,"date":"2017-08-18T14:45:08","date_gmt":"2017-08-18T19:45:08","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=332"},"modified":"2018-07-28T16:32:24","modified_gmt":"2018-07-28T21:32:24","slug":"python-on-the-web-how-to-delete-cookies-in-a-cgi-script","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/08\/18\/python-on-the-web-how-to-delete-cookies-in-a-cgi-script\/","title":{"rendered":"Python on the web: How to delete cookies in a CGI script"},"content":{"rendered":"<p>After you have a cookie that has been <a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/08\/09\/python-on-the-web-how-to-set-cookies-in-a-cgi-script\/\">set<\/a>, here is how you can delete it.<\/p>\n<p>The trick is to send an update to the cookie where you feed it an expiration date that is already in the past. For example:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">print \"Set-Cookie: xml_edit_tool=Value of cookie; 'expires=Wed, 28 Aug 2013 18:30:00 GMT' \\r\\n\"<\/code><\/p>\n<p>Note: When you set this cookie update, you have to use the name of the cookie, in this case it would be &#8216;xml_edit_tool&#8217;.<\/p>\n<p>Here is complete code for a function that can delete cookies based on the cookie name:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!C:\\Python27\\python.exe -u\r\n\r\ndef delete_cookie(cookie_name):\r\n\u00a0\u00a0\u00a0 \"\"\"Pass the name of the cookie you want deleted and this function will delete it.\"\"\"\r\n\u00a0\u00a0\u00a0 # Date from the past\r\n\u00a0\u00a0\u00a0 expired_date = 'expires=Wed, 28 Aug 2013 18:30:00 GMT'\r\n\u00a0\u00a0\u00a0 print \"Set-Cookie: %s=This could be anything. The important part is the key name xml_edit_tool; %s \\r\\n\" % (cookie_name, expired_date)\r\n\r\ndelete_cookie('xml_edit_tool')\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After you have a cookie that has been set, here is how you can delete it. The trick is to send an update to the cookie where you feed it an expiration date that is already in the past. For example: print &#8220;Set-Cookie: xml_edit_tool=Value of cookie; &#8216;expires=Wed, 28 Aug 2013 18:30:00 GMT&#8217; \\r\\n&#8221; Note: When &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/08\/18\/python-on-the-web-how-to-delete-cookies-in-a-cgi-script\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Python on the web: How to delete cookies in a CGI script<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,22],"tags":[16,17,4],"class_list":["post-332","post","type-post","status-publish","format-standard","hentry","category-python-cgi","category-python-language","tag-cgi","tag-cookies","tag-python"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=332"}],"version-history":[{"count":7,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":339,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/332\/revisions\/339"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}