当前位置:主页 > 软件编程 > Python代码 >

python开启debug模式的方法

时间:2020-10-24 11:42:48 | 栏目:Python代码 | 点击:

python开启debug模式的代码如下所示:

import requests
 session = requests.session()
import logging
import requests
logging.basicConfig(level=logging.DEBUG,
     format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
     datefmt='%a, %d %b %Y %H:%M:%S',
     filename='myapp.log',
  filemode='w')
logging.debug(session.get('http://www.qq.com'))
logging.debug(session.get('http://www.qq.com'))

运行结果:

Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:205] DEBUG Starting new HTTP connection (1): www.qq.com:80
Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:393] DEBUG http://www.qq.com:80 "GET / HTTP/1.1" 302 168
Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:813] DEBUG Starting new HTTPS connection (1): www.qq.com:443
Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:393] DEBUG https://www.qq.com:443 "GET / HTTP/1.1" 200 None
Mon, 26 Nov 2018 02:31:08 server_t2.py[line:17] DEBUG <Response [200]>
Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:393] DEBUG http://www.qq.com:80 "GET / HTTP/1.1" 302 168
Mon, 26 Nov 2018 02:31:08 connectionpool.py[line:393] DEBUG https://www.qq.com:443 "GET / HTTP/1.1" 200 None
Mon, 26 Nov 2018 02:31:08 server_t2.py[line:18] DEBUG <Response [200]>

用来测试每次请求,看是不是长链接,记录下debug怎么设置。

总结

您可能感兴趣的文章:

相关文章