Mridang Agarwalla
Mridang Agarwalla

Reputation: 44978

Get filename when using urllib.urlopen

I'm using urllib.urlopen to read a file from a URL. What is the best way to get the filename? Do servers always return the Content-Disposition header?

Thanks.

Upvotes: 1

Views: 654

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798566

It's an optional header, so no. See if it exists, and if not then fall back to checking the URL.

Upvotes: 1

Related Questions