相关疑难解决方法(0)

如何禁用python警告

我正在处理代码,并使用warnings库抛出了很多(对我而言)无用的警告.阅读(/扫描)文档我只发现了一种禁用单个函数警告的方法.但我不想改变这么多的代码.

可能有旗帜python -no-warning foo.py吗?

你会推荐什么?

python suppress-warnings

350
推荐指数
11
解决办法
49万
查看次数

如何禁用Requests库中的日志消息?

默认情况下,Requests python库将日志消息写入控制台,其行如下:

Starting new HTTP connection (1): example.com
http://example.com:80 "GET / HTTP/1.1" 200 606
Run Code Online (Sandbox Code Playgroud)

我通常对这些消息不感兴趣,并希望禁用它们.什么是沉默这些消息或减少请求的冗长的最佳方法?

python logging verbosity python-requests

336
推荐指数
8
解决办法
12万
查看次数

如何在Python中为特定模块实现不同的级别

从这个stackoverflow问题,如何实现以下配置文件?

[logger_qpid]
level=NOTSET
handlers=nullHandler
qualname=qpid
propagate=0
Run Code Online (Sandbox Code Playgroud)

我正在使用logging.basicConfig:

# Configure parser.
parser = argparse.ArgumentParser(description = 'Allow for debug logging mode.')
parser.add_argument('--debug', action = 'store_true',
                    help = 'Outputs additional information to log.')
c_args = parser.parse_args()
# Configure logging mode.
if c_args.debug:
    # Enable debug level of logging.
    print "Logging level set to debug."
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.DEBUG)
else:
    logging.basicConfig(filename = LOG_FILENAME, format = '%(asctime)s %(message)s',
                        level = logging.INFO)
Run Code Online (Sandbox Code Playgroud)

logging module python-2.x

14
推荐指数
1
解决办法
9243
查看次数

如何更新certifi的根证书?

我正在使用 certifi python 模块来验证 ssl 连接。我查看了 certifi (python2.7/site-packages/certifi/cacert.pem) 中包含的根证书,其中一些证书已过期。如何更新这些证书?我尝试使用 pip 更新 certifi 包,但这只会更新包而不是根 CA 文件。

python ssl urllib root-certificate certifi

7
推荐指数
1
解决办法
2万
查看次数

Python InsecureRequestWarning真正意味着什么?

我收到了警告:

/.../local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:734: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
Run Code Online (Sandbox Code Playgroud)

我在读文件.

如果我知道自己在做什么,就像这个一样,我会看到很多关于如何禁用它的帖子.

但我仍然无法弄清楚错误的含义.我认为这意味着我错过了证书(因为它只发生在我的VPS上,而不是我的Mac上运行相同版本的脚本),但我不明白为什么我需要证书才能发出安全请求到第三方API.

非常感谢一个有用的摘要(或只是正确方向上的一点),所以我可以决定是否禁用它.我的直觉是我不应该禁用它,所以我想弄清楚如何正确解决问题.

python ssl-certificate urllib3

4
推荐指数
1
解决办法
3766
查看次数

可以在请求模块中禁用 InsecureRequestWarnings 吗?

这篇文章解释了如何禁用 urllib3 中的警告,但我使用的是session带有请求模块的对象。出现警告是因为verify(ssl) 参数设置为False为了访问页面。

例如

url = "https://www.booking.com/searchresults.en-gb.html"

querystring = {"label":"gen173nr-1DCAEoggJCAlhYSDNiBW5vcmVmcgV1c19vcogBAZgBMbgBB8gBDdgBA-gBAfgBApICAXmoAgM","lang":"en-gb","sid":"5f9b0b3af27a0a0b48017c6c387d8224","track_lsso":"2","sb":"1","src":"searchresults","src_elem":"sb","error_url":"https://www.booking.com/searchresults.en-gb.html?label=gen173nr-1DCAEoggJCAlhYSDNiBW5vcmVmcgV1c19vcogBAZgBMbgBB8gBDdgBA-gBAfgBApICAXmoAgM;sid=5f9b0b3af27a0a0b48017c6c387d8224;class_interval=1;dest_id=30;dest_type=country;dtdisc=0;group_adults=1;group_children=0;inac=0;index_postcard=0;label_click=undef;mih=0;no_rooms=1;offset=0;postcard=0;raw_dest_type=country;room1=A;sb_price_type=total;src=searchresults;src_elem=sb;ss=" + country + ";ss_all=0;ssb=empty;sshis=0;ssne=" + country + ";ssne_untouched=" + country + "&;","ss":country,"ssne":country,"ssne_untouched":country,"dest_id":"30","dest_type":"country","checkin_monthday":"","checkin_month":"","checkin_year":"","checkout_monthday":"","checkout_month":"","checkout_year":"","room1":"A","no_rooms":"1","group_adults":"1","group_children":"0"}

headers = {
        'upgrade-insecure-requests': "1",
        'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36",
        'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        'referer': "https://www.booking.com/searchresults.en-gb.html?label=gen173nr-1DCAEoggJCAlhYSDNiBW5vcmVmcgV1c19vcogBAZgBMbgBB8gBDdgBA-gBAfgBApICAXmoAgM&lang=en-gb&sid=5f9b0b3af27a0a0b48017c6c387d8224&track_lsso=2&sb=1&src=searchresults&src_elem=sb&error_url=https%3A%2F%2Fwww.booking.com%2Fsearchresults.en-gb.html%3Flabel%3Dgen173nr-1DCAEoggJCAlhYSDNiBW5vcmVmcgV1c19vcogBAZgBMbgBB8gBDdgBA-gBAfgBApICAXmoAgM%3Bsid%3D5f9b0b3af27a0a0b48017c6c387d8224%3Bclass_interval%3D1%3Bdest_id%3D30%3Bdest_type%3Dcountry%3Bgroup_adults%3D1%3Bgroup_children%3D0%3Blabel_click%3Dundef%3Bmih%3D0%3Bno_rooms%3D1%3Boffset%3D0%3Braw_dest_type%3Dcountry%3Broom1%3DA%3Bsb_price_type%3Dtotal%3Bsrc%3Dsearchresults%3Bsrc_elem%3Dsb%3Bss%3D" + country + "%3Bssb%3Dempty%3Bssne%3D" + country + "%3Bssne_untouched%3D" + country + "%26%3B&ss=" + country + "&ssne=" + country + "&ssne_untouched=" + country + "&dest_id=30&dest_type=country&checkin_monthday=&checkin_month=&checkin_year=&checkout_monthday=&checkout_month=&checkout_year=&room1=A&no_rooms=1&group_adults=1&group_children=0",
        'content-Encoding': "br",
        'accept-language': …
Run Code Online (Sandbox Code Playgroud)

python ssl warnings python-requests

3
推荐指数
1
解决办法
4541
查看次数