PythonSMTP.starttls参数

2024-04-19 21:33:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手。我对python的duck类型做了一些研究,现在遇到了如下这种情况。在

当我查看python标准库时,我发现api只指定了参数的名称,这些参数似乎暗示了要传递的内容,但是类型。这让我依赖直觉。所以当我把错误的对象传递到函数中时,听起来就像是在玩一个反复试验的游戏。在

例如,在python标准库smtplib中,我希望使用以下函数:

SMTP.starttls([keyfile[, certfile]])

但我不知道应该将什么类型的对象传递给keyfile或certfile参数?我怎么解决这个问题?在


Tags: 对象函数名称api类型内容参数标准
1条回答
网友
1楼 · 发布于 2024-04-19 21:33:15

这可能只是对Python和文档不熟悉,而不是duck类型问题。在

在您的特定示例中,您必须稍微遵循文档。在

SMTP.starttls()方法中,it says

If keyfile and certfile are provided, these are passed to the socket module’s ssl() function.

如果您点击该链接,您将看到:

The keyfile and certfile parameters specify optional files which contain a certificate to be used to identify the local side of the connection. See the discussion of Certificates for more information on how the certificate is stored in the certfile.

编辑:参数keyfilecertfile参数似乎是文件名(字符串)。如果您随后跟随Certificates的链接,您将看到这些文件应该是PEM格式的。在

感谢J.F.塞巴斯蒂安的建议。在

相关问题 更多 >