2

I am trying to download files from a site that requires htaccess - style authentication as well as a cookie, and am using python mechanize to download these files. is there a way to start writing before loading the whole file into memory?

edit: I'm using a mechanize.Browser to keep track of the auth/cookie, so either I need a way to use the Browser state when calling urlopen or a better way to user Browser.

edit2: wound up rewriting using urllib2, but am still mildly curious if there was an easy solution.

user1036542
  • 149
  • 1
  • 5

1 Answers1

-1

Assuming you're using urllib2 to make the http connection, the answer is yes. urlopen() returns a file-like object, from which you can read() chunks of data that can be written to disk one at a time.

ʇsәɹoɈ
  • 22,757
  • 7
  • 55
  • 61
  • can i get the cookies and auth headers from mechanize.Browser into urllib2? otherwise I'm not sure how urlopen helps. – user1036542 Jun 18 '12 at 00:58