xtream1101 / humblebundle-downloader

Download you Humble Bundle Library
MIT License
543 stars 63 forks source link

"Malformed" cookies.txt causes confusing traceback #32

Closed evanpowers closed 3 years ago

evanpowers commented 3 years ago

I'd like to suggest two small changes as a result of my experience getting started with hbd:

  1. Log a warning about the cookie file not being in Netscape format when employing the "original cookie method" fallback, OR do a format check on the file data to verify it isn't a not-correct-enough Netscape format file. Something very basic and crude like if '\tTRUE\t' in f.read().upper(): raise SomeError() would do the trick, I'd think.
  2. Mention in README.md that the cookie loader is pedantic and the below curl command can fix such problems if you have them.

Backstory follows:

As in issues #29 and #30 I used the Cookie Quick Manager add-on for Firefox (configured to export using the Netscape template) to obtain my cookies.txt. However, it seems http.cookiejar.MozillaCookieJar is too picky about the file format to load my file as-is, and the resulting LoadError exception caused hbd to silently fall back on the "original cookie method," ultimately resulting in the requests module raising an uncaught exception about leading/trailing whitespace in the cookie header. I guess from the newline at the end of the file.

I was ultimately able to resolve my problem by round-tripping the cookies through curl; diffing the two cookie files makes me think the problem has to do with lines that rely on tail matching....

curl -b cookies.orig.txt --cookie-jar cookies.txt http://bogus