Quiz
- Don't we set the session variable to resp.cookies? And can't we also create a session object to do sessions? One of the readings mentioned that. What are the differences between the answer options for Q3?
Here's the question again:
How do we do sessions using the requests module? a. create a session object b. set the session variable c. create a cookie d. send back cookies it sent us
For (a) and (b) there is a session object (variable) in Flask, but not in the
Requestsmodule. You only have the cookies to work with.For (c), it's the cookie created by Flask that really holds our session information.
So the answer is (d).
- How would we handle multiple concurrent requests to the same server using the requests module, and would that cause any threading issues? Also what's the difference between using resp.text and resp.json()?
What a great question! Yes, we could combine threading and the requests module to do asynchronous requests. Very clever!
If they were all to the same server, we would definitely be stress-testing its handling of concurrency. We might not gain much in speed/latency depending on where the bottlenecks are.
If they were to different servers (some kind of web crawler), then we might gain a lot in concurrency.