Exploring the Benefits of requests
00:00
Now you’ll look into the requests library. While urllib is great because it’s built in, requests is the industry standard for interacting with HTTP in Python. In this section, you’ll see the main benefits of using this library, how to dynamically build URLs using query parameters so you aren’t manually stitching strings together, and how to verify that your request was actually successful before you try to use the data.
00:27
requests is the go-to tool for Python developers in most cases. The main reason is that it’s designed to be Pythonic. It basically means that the code looks and behaves the way a Python programmer expects.
00:38
It’s intuitive and readable. It also offers much better error handling than the standard library, has built-in support for things like persistent sessions and cookies, and has a massive community backing it, so if you search online for help, you’ll almost always find a requests example first.
00:56
However, it’s important to remember that because requests is a third-party library, it doesn’t come pre-installed with Python. You’ll need to install it on your system.
01:07
Don’t worry about opening your terminal just yet. I’ll walk you through the installation process step by step in the next lesson, but before we get to that installation, let’s look at a specific scenario where urllib can get messy, but where requests shines: handling dynamic URLs.
01:24
Let’s learn a bit more about it. Often, the file you want isn’t a static address like data.zip. Instead, you might need to query an API, pass in a specific file ID, or provide an API key.
01:39 We’re going to look at how to handle this cleanly using query parameters. Let’s dive into a quick coding example.
Become a Member to join the conversation.
