如何关闭 python 中的所有警告
How to turn off all warning in python
我有这个代码:
import nsepython
import warnings
warnings.filterwarnings("ignore")
print(nse_quote_ltp("RELIANCE"))
此代码在打印出结果之前发出此警告:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
www.nseindia.com:443
DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET
/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O HTTP/1.1" 200
26695 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
www.nseindia.com:443
DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET
/api/quote-derivative?symbol=RELIANCE HTTP/1.1" 200 38950
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
www.nseindia.com:443
DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET
/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O HTTP/1.1" 200
26695 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):
www.nseindia.com:443
DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET
/api/quote-derivative?symbol=RELIANCE HTTP/1.1" 200 38950
2387
如何关闭此警告?
您将日志记录级别设置为 DEBUG,如果您使用的是像 Flask 这样的框架,它将使用 Python 的内置日志记录机制在适当的级别输出消息。试试这个:
import nsepython
import warnings
import logging
logging.basicConfig(level=logging.ERROR)
warnings.filterwarnings("ignore")
print(nse_quote_ltp("RELIANCE"))
我有这个代码:
import nsepython
import warnings
warnings.filterwarnings("ignore")
print(nse_quote_ltp("RELIANCE"))
此代码在打印出结果之前发出此警告:
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.nseindia.com:443 DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET /api/equity-stockIndices?index=SECURITIES%20IN%20F%26O HTTP/1.1" 200 26695 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.nseindia.com:443 DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET /api/quote-derivative?symbol=RELIANCE HTTP/1.1" 200 38950 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.nseindia.com:443 DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET /api/equity-stockIndices?index=SECURITIES%20IN%20F%26O HTTP/1.1" 200 26695 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.nseindia.com:443 DEBUG:urllib3.connectionpool:https://www.nseindia.com:443 "GET /api/quote-derivative?symbol=RELIANCE HTTP/1.1" 200 38950
2387
如何关闭此警告?
您将日志记录级别设置为 DEBUG,如果您使用的是像 Flask 这样的框架,它将使用 Python 的内置日志记录机制在适当的级别输出消息。试试这个:
import nsepython
import warnings
import logging
logging.basicConfig(level=logging.ERROR)
warnings.filterwarnings("ignore")
print(nse_quote_ltp("RELIANCE"))