{"action":"created","issue":{"url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/7","labels_url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/7/comments","events_url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/7/events","html_url":"https://github.com/n8henrie/pycookiecheat/pull/7","id":94851981,"number":7,"title":"Correctly match all domains and wildcard domains","user":{"login":"brandon-rhodes","id":166162,"avatar_url":"https://avatars.githubusercontent.com/u/166162?v=3","gravatar_id":"","url":"https://api.github.com/users/brandon-rhodes","html_url":"https://github.com/brandon-rhodes","followers_url":"https://api.github.com/users/brandon-rhodes/followers","following_url":"https://api.github.com/users/brandon-rhodes/following{/other_user}","gists_url":"https://api.github.com/users/brandon-rhodes/gists{/gist_id}","starred_url":"https://api.github.com/users/brandon-rhodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandon-rhodes/subscriptions","organizations_url":"https://api.github.com/users/brandon-rhodes/orgs","repos_url":"https://api.github.com/users/brandon-rhodes/repos","events_url":"https://api.github.com/users/brandon-rhodes/events{/privacy}","received_events_url":"https://api.github.com/users/brandon-rhodes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-14T02:13:48Z","updated_at":"2015-07-15T07:11:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/n8henrie/pycookiecheat/pulls/7","html_url":"https://github.com/n8henrie/pycookiecheat/pull/7","diff_url":"https://github.com/n8henrie/pycookiecheat/pull/7.diff","patch_url":"https://github.com/n8henrie/pycookiecheat/pull/7.patch"},"body":"I was not able to log into a web site because it created cookies beneath the `example.com` level, putting several of them instead down at the `foo.example.com` level for the particular service it was trying to access. Furthermore, some of them were specified using the wildcard `.foo.example.com` so that they would be delivered to subdomains of `foo` as well — but a leading `.` was not previously allowed by this library, meaning that these cookies were left out of my requests.\r\n\r\nThis patch descends through the possible domain name matches in the same order that a browser should, and allows my Python script to successfully authenticate to the service that I was previously locked out of!\r\n\r\nAlso, this tweaks the code to avoid a possible encoding problem with hand-quoted domain names that include special characters — by relying on the sqlite3 \"?\" quoting character to get the quoting correct."},"comment":{"url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/comments/121511936","html_url":"https://github.com/n8henrie/pycookiecheat/pull/7#issuecomment-121511936","issue_url":"https://api.github.com/repos/n8henrie/pycookiecheat/issues/7","id":121511936,"user":{"login":"n8henrie","id":1234956,"avatar_url":"https://avatars.githubusercontent.com/u/1234956?v=3","gravatar_id":"","url":"https://api.github.com/users/n8henrie","html_url":"https://github.com/n8henrie","followers_url":"https://api.github.com/users/n8henrie/followers","following_url":"https://api.github.com/users/n8henrie/following{/other_user}","gists_url":"https://api.github.com/users/n8henrie/gists{/gist_id}","starred_url":"https://api.github.com/users/n8henrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/n8henrie/subscriptions","organizations_url":"https://api.github.com/users/n8henrie/orgs","repos_url":"https://api.github.com/users/n8henrie/repos","events_url":"https://api.github.com/users/n8henrie/events{/privacy}","received_events_url":"https://api.github.com/users/n8henrie/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T07:11:37Z","updated_at":"2015-07-15T07:11:37Z","body":"Ha, I hadn't realized that [it was you](http://n8henrie.com/2013/11/use-chromes-cookies-for-easier-downloading-with-python-requests/#comment-1864441284) who had originally prompted me to make subdomian-cookie-related-changes (and an official repository) in the first place. Thanks for your continued interest in (and contribution to) the project!\r\n\r\nOkay, I think I understand what the issue is now. I had initially misunderstood that it was not pulling in the appropriate cookies, which surprised me as the prior changes to subdomain handling made it work *very* broadly by trying to pull in all cookies from all domains. I think that's now the cause the problem --  being mutable, the `cookies.update(cookies_list)` is overwriting the subdomain cookie when it finds the domain cookie (or any other subdomain cookie) after the subdomain-of-interest cookie. Your PR looks like a great fix for this, by going from least to most specific WRT domain -> subdomain.\r\n\r\nTo me, it is most important for `pycookiecheat` to work simply and reliably, for myself and for end users. It's okay with me if it pulls in additional, unnecessary cookies for less specific subdomains, if this helps at times and doesn't hurt in the rest. I think this behavior is well modeled by your PR.\r\n\r\nBefore I merge, could you explain what's going on with the `is_country_tld` part? Is there some reason ccTLDs should only have subdomains pulled in? This seems like it would be problematic if a user were to use it for e.g. `chrome_cookies(http://last.fm)` (returns `[]`), and I don't understand why you put in that change in behavior for those domains."}}