I am facing a problem in my cherrypy APIs for a web application, where there is a redirection to external site within my primary domain, and it is setting a cookie which is not in valid format and in turn causing subsequent API request to fail.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</meta>
<title>400 Bad Request</title>
<style type="text/css">
#powered_by {
margin-top: 20px;
border-top: 2px solid black;
font-style: italic;
}
#traceback {
color: red;
}
</style>
</head>
<body>
<h2>400 Bad Request</h2>
<p>Illegal key 'set)|firstTouchURL'</p>
<pre id="traceback">Traceback (most recent call last):
File "/home/servs/.pyenv/versions/3.9.0/envs/prod-3.9.0/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 734, in process_headers
self.cookie.load(value)
File "/home/servs/.pyenv/versions/3.9.0/lib/python3.9/http/cookies.py", line 532, in load
self.__parse_string(rawdata)
File "/home/servs/.pyenv/versions/3.9.0/lib/python3.9/http/cookies.py", line 596, in __parse_string
self.__set(key, rval, cval)
File "/home/servs/.pyenv/versions/3.9.0/lib/python3.9/http/cookies.py", line 488, in __set
M.set(key, real_value, coded_value)
File "/home/servs/.pyenv/versions/3.9.0/lib/python3.9/http/cookies.py", line 353, in set
raise CookieError('Illegal key %r' % (key,))
http.cookies.CookieError: Illegal key 'set)|firstTouchURL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/servs/.pyenv/versions/3.9.0/envs/prod-3.9.0/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 638, in respond
self._do_respond(path_info)
File "/home/servs/.pyenv/versions/3.9.0/envs/prod-3.9.0/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 666, in _do_respond
self.process_headers()
File "/home/servs/.pyenv/versions/3.9.0/envs/prod-3.9.0/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 736, in process_headers
raise cherrypy.HTTPError(400, str(exc))
cherrypy._cperror.HTTPError: (400, "Illegal key 'set)|firstTouchURL'")
</pre>
<div id="powered_by">
<span>
Powered by <a href="http://www.cherrypy.org">CherryPy 18.6.0</a>
</span>
</div>
</body>
</html>
Where that illegal character is space.
I tried removing that character and send API requests through postman and they were successful. I tried removing space manually in browser through developer tools, which works. clearing cookies for the primary domain in the browser works. Incognito tab on the browser works.
Is there any better approach to solve this without any of these manual intervention.