Requests Introduction & Overview
In this lesson you’ll get a general overview about the requests
library. Furthermore, it reveals you how to install requests
on your machine using pip and how to import it. In fact it’s as easy as:
$ pip install requests
After installing requests
you’re able to import into your project via:
import requests
When you’ve completed the course, take our interactive quiz to check your learning progress:
Take the Quiz: Test your knowledge with our interactive “HTTP Requests With the "requests" Library” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
HTTP Requests With the "requests" LibraryTest your understanding of the Python "requests" library for making HTTP requests and interacting with web services.
00:00
Hi, this is Chris Bailey. I’m going to be taking you through Python’s requests
library. This is Section 1 of 3, and it will be getting started with requests
, introducing the GET
request, and processing responses—talking about status codes, and content, and headers.
00:15
A couple of quick details about requests
. The subtitle is HTTP for Humans™. It was created by Kenneth Reitz, and this is a link to the docs.
00:25
So, why learn about requests
? It’s the defacto standard for making HTTP requests in Python. It’s a beautifully simple API, it abstracts the complicated parts of HTTP, and it focuses on interaction with services. So, what do you need to know for this tutorial?
00:40
Just a basic knowledge of HTTP. You can get that from a link that’s in the article, or I’m repeating it right here, from W3Schools. All right, let’s get started. The first step is to install requests
. To do that we’re going to use pip
, and it’s simply pip install requests
.
00:57
As you can see here, I’ve already installed it on this machine. Let’s step into a REPL. The one I’m using is called bpython
.
01:05 Let’s make sure it worked. We’ll go ahead and import it.
01:10
All right, looks like it’s successful. Great! Let’s get started with the GET
request.
Chris Bailey RP Team on March 15, 2019
Thanks so much Dominic! I’m really getting mileage out of bptyhon, its fantastic for inspecting elements.
Evan E on May 1, 2019
Yeah, big ups on bpython. I’ve been using bpython since Dan Bader showed it back when he use to make YouTube vids;)
Dri on Oct. 15, 2019
Hi @ll, what’s the best way to install bpython? I’m getting error on homebrew and pip3…
emalfiza on Jan. 24, 2020
Hey Christ, why the bpython installation doesnt work? I tried in my Mac terminal and even in PyCharm terminal?
Chris Bailey RP Team on Jan. 24, 2020
Hi @emalfiza. I’m sorry you are having trouble with bpython. What type of error are you getting? What version of Python do you have, is it a version from Python.org
or a different distribution, and which version of macOS? I have had lots of issues of late installing libraries/packages and python itself, as I had to start over with a new drive (SSD) in my Mac. Two of the problems I had involved for one the inability to compile the version of the package on my machine, and the other had to do with not having certificates installed. For the compiling I needed to update Xcode libraries, which the error I got in the terminal walked me through. The other issue with certificates had to do with the version of Python not automatically installing those certificates, and needing to go into the folder where Python is installed and click to run, Install Certificates.command.
In general the best method of installing is using python3 -m pip install bpython
, but it would help to know what errors you are getting.
emalfiza on Jan. 24, 2020
Hey @ChristBailey grateful of your reply to the issue.
I have the Python3 3.8.0 version install in my MacOS Catalina version 10.15.2 and I have downloaded python3 from python.org.
I tried the commands that you have used in the HTTP requests module plus the python3 -m pip install bpython and as will as python3 -m pip3 install bpython, but no joy.
The errors that I get is really verbose:
ERROR: Command errored out with exit status 1:
command: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/hs/6gnsjkyn4wb27ztcqrvr_mrh0000gn/T/pip-install-_kxafe8y/greenlet/setup.py'"'"'; __file__='"'"'/private/var/folders/hs/6gnsjkyn4wb27ztcqrvr_mrh0000gn/T/pip-install-_kxafe8y/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/hs/6gnsjkyn4wb27ztcqrvr_mrh0000gn/T/pip-record-167v2edn/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/greenlet
cwd: /private/var/folders/hs/6gnsjkyn4wb27ztcqrvr_mrh0000gn/T/pip-install-_kxafe8y/greenlet/
Complete output (9 lines):
running install
running build
running build_ext
building 'greenlet' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.8
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c greenlet.c -o build/temp.macosx-10.9-x86_64-3.8/greenlet.o
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
By the way I really loved and enjoyed your tutorials.
Chris Bailey RP Team on Jan. 24, 2020
Hi @emalfiza, It looks like you are having a gcc compiler issue, but I’m not positive. The section (error:invalid active developer path(....CommandLineTools)) is referring to it being unable to find those tools I think. If you recently upgraded to Catalina, it can sometimes remove the tools, or makes other changes so that they don’t work. There is a terminal command to re-install them. xcode-select --install
Here is a thread with more about it I found. I hope this helps.
Become a Member to join the conversation.
Dominic on March 14, 2019
Hi Chris, thanks for the tutorial :-) Getting to know bpython was already worth so much! I didn’t know it so far but it already helped me today to get an effortless look into some module functions!