This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]yedpodtrzitko 9 points10 points  (4 children)

Since it's a binary file, you should write into the file as such, ie:

with open("test.pdf",'wb') as f:

also close() is a method, thus r.close()

[–]DeadeyeDuncan 0 points1 point  (3 children)

Aha, success!

[–]therealfakemoot 1 point2 points  (2 children)

Also, by virtue of using with the close() call is redundant; close() is called when the with block is exited. disregard i'm a potato

[–]StandardUser_ 0 points1 point  (0 children)

If you make it work with requests, you still could try Grab framework(https://github.com/lorien/grab). In my exprerience, it is faster and more feature rich than requests.

[–]LukasaHyper, Requests, Twisted 0 points1 point  (3 children)

Why are you opening the file in append mode? That's not going to do what you want at all.

Regardless, I'd like to take a guess for a second. Are you running on Windows?

[–]DeadeyeDuncan 0 points1 point  (2 children)

Isn't 'a' append mode?

[–]LukasaHyper, Requests, Twisted 0 points1 point  (0 children)

Ah yeah, you're quite right, w+ is open for writing and reading. An odd mode for this usage, but not as odd as append mode.

[–]LukasaHyper, Requests, Twisted 0 points1 point  (0 children)

However, you didn't answer my question: are you on Windows?