Downloading wmv from a url in Python 2.6

322 views Asked by At

I have a wmv file at a particular url that I want to grab and save as a file using Python. My script uses urllib2 to authenticate and read the bytes and save them locally in chunks. However, once I open the file, no video player recognizes it. When I download the wmv manually from a browser, the file plays fine, but oddly enough ends up being about 500kb smaller than the file I end up with using Python. What's going on? Is there header information I need to somehow exclude?

3

There are 3 answers

1
dustinl4m3 On

What Transfer-Encoding is the server sending back? I would bet it is sending back Transfer-Encoding: chunked, which is ending up in your data.

http://en.wikipedia.org/wiki/Chunked_transfer_encoding

0
Noah On

From what I understand, urllib works at the HTTP level and should properly remove headers in subsequent chunks. I took a look at the data returned by read() and it's all bytes.

0
Noah On

I was writing my file with mode 'w' on a Windows machine. Writing binary data should be done with mode 'wb' or the EOLs will be incorrect.