课程: Python Essential Libraries
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Advanced features
- Okay, I'm going to wrap up our quick introduction to the requests library by examining a few of the more advanced features that it provides. And the first one of these features is the ability to specify a timeout for a given request. And in fact, in normal production use, you should be using timeouts anyway to make sure your application stays responsive. So, lets go ahead and open up the advreqs_start file. And, to do this with requests, we are going to start by constructing a simple request, like we've done several times now. So I'll call "requests.get", and I'm going to be using the "httpbin" testing website that we've been using and I'm going to access the endpoint that gives me a delay and I'm going to ask for a delay of .5 seconds. And then, I'm going to set a timeout value of 1 second. All right? And then, after that happens, I'll just go ahead and print the response status code. What I'm essentially doing here…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。