Do you know about inspecting a request you just sent? If not, this lesson is right for you! To give you sense of how to do it, let’s have a look at how to get the URL of the request you sent:
>>> response.request.url
Do you know about inspecting a request you just sent? If not, this lesson is right for you! To give you sense of how to do it, let’s have a look at how to get the URL of the request you sent:
>>> response.request.url
00:00
The requests
library prepares the request before sending it to the server. An example of some of the things that it would prepare would be to validate the headers, to serialize JSON content—like we talked about before. To look at the PreparedRequest
, you use the method .request
—for example, response.request.url
.
00:18
Let’s try it out! To inspect our PreparedRequest
we just need to make one, so let’s save it into a response
again. Since we’re just focusing on this, let’s just go ahead and put it into a post()
and type the URL directly. This time.
00:34
we’ll send the data as JSON and just put a really simple key and value pair here. All right. Let’s look at our response
—success. Great! So, the Response
will have the PreparedRequest
inside of it—again, we access it from .request
—and then if we put another dot (.
) on here we can see all the different other methods that are available. So we can say, “What was the URL for that?
Become a Member to join the conversation.