简体   繁体   English

请求:cert 和 verify 有什么区别?

[英]Requests: what is the difference between cert and verify?

What is the difference between cert and verify? cert 和 verify 有什么区别?

From Documentation:从文档:

verify – (optional) if True, the SSL cert will be verified. verify –(可选)如果为 True,将验证 SSL 证书。 A CA_BUNDLE path can also be provided.还可以提供 CA_BUNDLE 路径。 cert – (optional) if String, path to ssl client cert file (.pem). cert –(可选)如果是字符串,则为 ssl 客户端证书文件 (.pem) 的路径。 If Tuple, ('cert', 'key') pair.如果是元组,则 ('cert', 'key') 对。

Does this mean I can do the following:这是否意味着我可以执行以下操作:

CA_BUNDLE='path/to/.pem'
requests.get(url=google.com, verify= CA_BUNDLE)

or或者

Cert='path/to/.pem'
requests.get(url=google.com, cert=Cert)

They both look like they do the same thing.他们俩看起来都在做同样的事情。 except verify can disable ssl verification.除了 verify 可以禁用 ssl 验证。

I am trying to compile my code to an exe using PYinstaller.我正在尝试使用 PYinstaller 将我的代码编译为 exe。 I am using certifi module that I see already has a cacert.pem file but I guess I still have to bundle it with my code.我正在使用我看到已经有一个 cacert.pem 文件的 certifi 模块,但我想我仍然必须将它与我的代码捆绑在一起。

In my code do I modify ...verify or cert?...with a path to cacert.pem or just 'cacert.pem'?在我的代码中,我是修改 ...verify 还是 cert?...使用 cacert.pem 的路径还是只是“cacert.pem”?

I think it is clearly stated in the documentation: http://www.python-requests.org/en/latest/user/advanced/#ssl-cert-verification我认为它在文档中明确说明:http: //www.python-requests.org/en/latest/user/advanced/#ssl-cert-verification

The option cert is to send you own certificate, eg authenticate yourself against the server using a client certificate.选项cert是向您发送自己的证书,例如使用客户端证书对服务器进行身份验证。 It needs a certificate file and if the key is not in the same file as the certificate also the key file.它需要一个证书文件,如果密钥与证书不在同一个文件中,则还需要密钥文件。

The option verify is used to enable (default) or disable verification of the servers certificate.选项verify用于启用(默认)或禁用服务器证书的验证。 It can take True or False or a name of a file which contains the trusted CAs.它可以采用 True 或 False 或包含受信任 CA 的文件的名称。 If not given I think (not documented?) it will take the default CA path/file from OpenSSL, which works usually on UNIX (except maybe OS X) and not on windows.如果没有给出,我认为(没有记录?)它将采用来自 OpenSSL 的默认 CA 路径/文件,它通常适用于 UNIX(可能除了 OS X)而不是 Windows。

if the *.pem file has this section如果*.pem文件有这个部分

-----BEGIN PRIVATE KEY-----
....
-----END PRIVATE KEY-----

then use cert然后使用cert


and if not, then use verify如果不是,则使用verify

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM