Get filename when using urllib.urlopen
Question
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.
Solution
It's an optional header, so no. See if it exists, and if not then fall back to checking the URL.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow