Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double quote Cookie is incorrect #851

Open
lisongkun opened this issue Dec 21, 2024 · 1 comment
Open

Double quote Cookie is incorrect #851

lisongkun opened this issue Dec 21, 2024 · 1 comment
Labels

Comments

@lisongkun
Copy link

I encountered an issue with cookies being enclosed in double quotes when implementing third-party website login using the Flurl dependency. However, Flurl automatically removes the double quotes, whereas Python Requests retains them. This discrepancy between the two parts in subsequent requests might be one of the reasons for my login failure, but I’m not sure. I need to eliminate each potential problem one by one. I tried the following code, but it had no effect, and the cookie even disappeared from the request headers.
compare

var cookie = session.Cookies.First(i => i.Name == "Y1vJ4IdorMglXdNk");
session.Cookies.Remove(i => i.Name == "Y1vJ4IdorMglXdNk");
session.Cookies.AddOrReplace(new FlurlCookie(cookie.Name, $"\"{cookie.Value}\"", cookie.OriginUrl));

trying code

I’m not sure if this is a bug in Flurl. Please provide me with a method to automatically handle wrapping cookies in double quotes, or tell me how to manually handle it.

@lisongkun lisongkun added the bug label Dec 21, 2024
@tmenier
Copy link
Owner

tmenier commented Dec 27, 2024

As I understand it, quotes around cookie values are optional and when a server sends a Set-Cookie response header with a quoted value, that does not obligate the client to quote the value when sending it back in the Cookie request header. If the server is not processing the unquoted value correctly, then I think that's where the bug is. Flurl's cookie session functionality isn't going to allow you to work around this very easily, unfortunately. You likely have to resort to using WithCookie or WithHeader to write the cookies explicitly each time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants