HTTP Cookie Conversion 2021-06-12 programming-languages Table of Contents cookie string to dictionary cookie dictionary to string cookie string to dictionary 1 from http.cookies import SimpleCookie 1 rawdata = 'sa-user-id=s%253A0-ef03aab2-d5bd-5b8c-50cd-a395819c57e1.a6YKYr5eOTh3f3vgcQJ3jVz540XviiIfrLMSZ8gSTmQ; sa-user-id-v2=s%253A7wOqstW9W4xQzaOVgZxX4bcLJAo.AaBzjGi%252FSqBzVUBWHWNyhlZugJhn1zViN4PYEycbpSE' 1 2 3 4 5 cookie = SimpleCookie() cookie.load(rawdata) cookies = {} for key, morsel in cookie.items(): cookies[key] = morsel.value 1 print(cookies) cookie dictionary to string 1 cookie_string = "; ".join([str(x)+"="+str(y) for x, y in cookies.items()]) Author Ye Zheng LastMod 2021-06-12 License CC BY-NC-ND 4.0