Requests Library Deep Dive - 2
File reviewed: api.py
Key Points:
- The main function used is
request(method, url, **kwargs)
. - All other methods internally call this function.
- The
request
function’s implementation is straightforward:
1
2
3
4
# By using the 'with' statement, we ensure the session is closed,
# avoiding open sockets that could trigger a ResourceWarning or appear as a memory leak.
with sessions.Session() as session:
return session.request(method=method, url=url, **kwargs)
- A session instance is created, and the request method is called on it.
- Next steps: Study the sessions module.