Forward WSGI cookies to Requests
<p>I am developing a WSGI middleware application (Python 2.7) using Werkzeug. This app works within a SAML SSO environment and needs a SAML token to be accessed. </p>

<p>The middleware also performs requests to other applications in the same SAML environment, acting on behalf of the logged in user. In order to do that without the need of user feedback, I need to forward the SAML session cookie that I can get from the WSGI environment to requests that I am performing using the Requests library. </p>

<p>My issue is that the cookies that I get from WSGI/Werkzeug can only be parsed as http.cookies.SimpleCooke , while Requests accepts cookielib.CookieJar instances. </p>

<p>I have not found a way to cleanly forward these session cookies without resorting to shameful hacks such as parsing the raw content of the set-cookie headers. </p>

<p>Any suggestions? </p>

<p>Thanks,</p>

<p>gm</p>

<p>Cookies are just <a href="https://tools.ietf.org/html/rfc6265#section-4.1" rel="nofollow">HTTP headers</a>. Just use pull the cookie value from http.cookies.SimpleCookie, and add it to your requests session's cookie <a href="http://docs.python-requests.org/en/master/_modules/requests/cookies/" rel="nofollow">jar</a>.</p>

<p>Not a hack. :)</p>

python python-requests session-cookies saml wsgi