{"id":329,"date":"2017-08-17T18:27:23","date_gmt":"2017-08-17T23:27:23","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=329"},"modified":"2019-06-15T12:42:28","modified_gmt":"2019-06-15T17:42:28","slug":"python-on-the-web-how-to-update-cookies-in-a-cgi-script","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2017\/08\/17\/python-on-the-web-how-to-update-cookies-in-a-cgi-script\/","title":{"rendered":"Python on the web: How to update cookies in a CGI script"},"content":{"rendered":"<p>Once you&#8217;ve <a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/08\/11\/python-on-the-web-how-to-get-cookies-in-a-cgi-script\/\">retrieved<\/a> a cookie via a function that returns the cookie as a dictionary of key value pairs, you can <em>update<\/em> the cookie in nearly the same way that you originally <a href=\"http:\/\/bluegalaxy.info\/codewalk\/2017\/08\/09\/python-on-the-web-how-to-set-cookies-in-a-cgi-script\/\">set<\/a> the cookie. The only difference is that this time you can set different values.<\/p>\n<p>In this example, I am passing the retrieved cookie to a function called <code>update_cookie()<\/code>, along with an updated &#8220;current_page&#8221; value:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def update_cookie(cookie_dict, current_page):\n    \"\"\"Updates the place value of existing cookie passed in.\"\"\"\n    c = Cookie.SimpleCookie()\n    user_value = cookie_dict['xml_edit_tool']\n    xml_file_value = cookie_dict['xml_file']\n    cookie_string = user_value+'|xml_file='+xml_file_value+'|place='+str(current_page)\n    c['xml_edit_tool'] = cookie_string\n    print c<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Once you&#8217;ve retrieved a cookie via a function that returns the cookie as a dictionary of key value pairs, you can update the cookie in nearly the same way that you originally set the cookie. The only difference is that this time you can set different values. In this example, I am passing the retrieved &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2017\/08\/17\/python-on-the-web-how-to-update-cookies-in-a-cgi-script\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Python on the web: How to update 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-329","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\/329","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=329"}],"version-history":[{"count":2,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":2784,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/329\/revisions\/2784"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}