Inspecting Metadata Requests
00:00
After saving the file, you might need to verify what you have. Just like you saw with urllib, the requests library gives you access to HTTP headers.
00:09
These headers serve as labels for the file, telling you what type of content it is, how big it is, and when it was last modified. You can get the header dictionary by typing response.headers and get any header using its corresponding key name. For example, if you want to get the content type, you can just do response.headers.get() and pass "Content-Type" as the argument.
00:33
Similarly, you can also grab "Content-Length", "Last-Modified", or any other header that’s been sent by the server. Keep in mind that HTTP headers are strings.
00:43 You might want to convert this to an integer if you want to use it for calculations or formatting. You can also provide a default value in case the header is missing.
00:53 So far, you’ve seen downloading files by loading the entire content into memory at once. For small files, this works just fine. But what if you need to download a 5GB dataset or a high-definition video?
01:06
That brings us to our next topic, streaming large downloads. In the next lesson, you’ll discuss why this is important, how to enable it in requests, and how to process the file in chunks.
Become a Member to join the conversation.
