{"id":624,"date":"2023-03-01T09:56:19","date_gmt":"2023-03-01T01:56:19","guid":{"rendered":"https:\/\/julyclyde.org\/?p=624"},"modified":"2023-03-01T09:56:19","modified_gmt":"2023-03-01T01:56:19","slug":"%e5%9c%a8python%e9%87%8c%e6%8a%91%e5%88%b6requests%e5%ba%93%e7%9a%84%e6%97%a5%e5%bf%97%e6%b6%88%e6%81%af","status":"publish","type":"post","link":"https:\/\/julyclyde.org\/?p=624","title":{"rendered":"\u5728Python\u91cc\u6291\u5236requests\u5e93\u7684\u65e5\u5fd7\u6d88\u606f"},"content":{"rendered":"\n<p>\u6211\u81ea\u5df1\u7ecf\u5e38\u5728\u81ea\u5df1\u7684\u811a\u672c\u5f00\u5934\u4f7f\u7528logging.basicConfig(level=logging.DEBUG)\u521d\u59cb\u5316logging\u5e93\uff0c\u4f46\u662f\u968f\u4e4b\u800c\u6765\u7684\u5c31\u662frequests\u4f1a\u8f93\u51fa\u5927\u91cf\u65e5\u5fd7\uff0c\u751a\u81f3\u76d6\u8fc7\u4e86\u6211\u81ea\u5df1\u7684\u5185\u5bb9\u3002\u6240\u4ee5\u6211\u6253\u7b97\u6291\u5236requests\u7684\u65e5\u5fd7\u3002<\/p>\n\n\n\n<p>\u7efc\u5408\u641c\u7d22\u7684\u8d44\u6599\uff0c\u548c\u63a2\u7d22\u6e90\u4ee3\u7801\uff0c\u6211\u53d1\u73b0\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u5b9erequests\u4ee3\u7801\u91cc\u6839\u672c\u5c31\u6ca1\u6709\u8c03\u7528\u4efb\u4f55logging\/logger\uff0c\u751a\u81f3\u5b83\u8fd8\u5728__init__.py\u91cc\u7ed9\u201c\u81ea\u5df1\u7684\u201dlogger\u8bbe\u7f6e\u4e86NullHandler<\/li>\n\n\n\n<li>docs\/api.rst \u6587\u6863\u91cc\u5176\u5b9e\u8bb2\u4e86\u600e\u4e48\u201c\u914d\u7f6e\u201d\u65e5\u5fd7\uff0c\u53ea\u662f\u6ca1\u6709\u201csupress\u201d\u8fd9\u4e2a\u8bcd\uff0c\u4ee5\u81f3\u4e8e\u6211\u6ca1\u641c\u5230<\/li>\n\n\n\n<li>\u901a\u8fc7\u5728Format\u91cc\u52a0\u4e0a%(name)s\uff0c\u53ef\u4ee5\u53d1\u73b0\u5199\u65e5\u5fd7\u7684\u5176\u5b9e\u662furllib3.connectionpool<\/li>\n<\/ul>\n\n\n\n<p>\u6240\u4ee5\u53ea\u9700\u8981\u5728basicConfig\u540e\u9762\u52a0\u4e00\u53e5<\/p>\n\n\n\n<p>logging.getLogger(&#8220;urllib3&#8221;).setLevel(logging.WARNING)<\/p>\n\n\n\n<p>\u5c31\u53ef\u4ee5\u6291\u5236\u8fd9\u90e8\u5206\u65e5\u5fd7\u4e86\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53e6\u5916\uff0clogging.Logger.manager.loggerDict\u662f\u4e2a\u597d\u4e1c\u897f\uff0c\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u5230\u5e95\u5b58\u5728\u54ea\u4e9blogger\u3002\u901a\u8fc7\u68c0\u67e5loggerDict[&#8216;urllib3.connectionpool&#8217;].propagate\u53d1\u73b0\u5176\u4e3aTrue\uff0c\u5176\u4e0a\u5c42\u4e5f\u662fTrue\uff0c\u56e0\u6b64\uff0c\u867d\u7136\u8fd9\u4e24\u5c42logger\u4e00\u4e2a\u6ca1handler\uff0c\u4e00\u4e2aNullHandler\uff0c\u4f46\u662f\u8be5logger\u8bb0\u5f55\u7684\u65e5\u5fd7\u6d88\u606f\u4ecd\u4f1a\u9010\u5c42\u4e0a\u4f20\uff0c\u6700\u7ec8\u88abbasicConfig\u7684root logger\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u81ea\u5df1\u7ecf\u5e38\u5728\u81ea\u5df1\u7684\u811a\u672c\u5f00\u5934\u4f7f\u7528logging.basicConfig(level=logging.DEBUG)\u521d\u59cb\u5316logging\u5e93\uff0c\u4f46\u662f\u968f\u4e4b\u800c\u6765\u7684\u5c31\u662frequests\u4f1a\u8f93\u51fa\u5927\u91cf\u65e5\u5fd7\uff0c\u751a\u81f3\u76d6\u8fc7\u4e86\u6211\u81ea\u5df1\u7684\u5185\u5bb9\u3002\u6240\u4ee5\u6211\u6253\u7b97\u6291\u5236requests\u7684\u65e5\u5fd7\u3002 \u7efc\u5408\u641c\u7d22\u7684\u8d44\u6599\uff0c\u548c\u63a2\u7d22\u6e90\u4ee3\u7801\uff0c\u6211\u53d1\u73b0\uff1a \u6240\u4ee5\u53ea\u9700\u8981\u5728basicConfig\u540e\u9762\u52a0\u4e00\u53e5 logging.getLogger(&#8220;urllib3&#8221;).setLevel(logging.WARNING) \u5c31\u53ef\u4ee5\u6291\u5236\u8fd9\u90e8\u5206\u65e5\u5fd7\u4e86\u3002 \u53e6\u5916\uff0clogging.Logger.manager.loggerDict\u662f\u4e2a\u597d\u4e1c\u897f\uff0c\u53ef\u4ee5\u68c0\u67e5\u5f53\u524d\u5230\u5e95\u5b58\u5728\u54ea\u4e9blogger\u3002\u901a\u8fc7\u68c0\u67e5loggerDict[&#8216;urllib3.connectionpool&#8217;].propagate\u53d1\u73b0\u5176\u4e3aTrue\uff0c\u5176\u4e0a\u5c42\u4e5f\u662fTrue\uff0c\u56e0\u6b64\uff0c\u867d\u7136\u8fd9\u4e24\u5c42logger\u4e00\u4e2a\u6ca1handler\uff0c\u4e00\u4e2aNullHandler\uff0c\u4f46\u662f\u8be5logger\u8bb0\u5f55\u7684\u65e5\u5fd7\u6d88\u606f\u4ecd\u4f1a\u9010\u5c42\u4e0a\u4f20\uff0c\u6700\u7ec8\u88abbasicConfig\u7684root logger\u5904\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[78,27,77],"class_list":["post-624","post","type-post","status-publish","format-standard","hentry","category-default","tag-logging","tag-python","tag-requests"],"_links":{"self":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts\/624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=624"}],"version-history":[{"count":0,"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions"}],"wp:attachment":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}