質問

I'm new to python. I've done some study on duck typing of python and I'm stuck in a situation like the following.

When I look in the Python standard library, I find the APIs specify only name of parameters which seem to give a hint on what to be passed but type. This makes me rely on intuition. So it sounds like I'm playing a trial-n-error game when i pass wrong object into function.

For example, in python standard library smtplib, i want to use this function:

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

But i don't know what type of object i should pass into keyfile or certfile parameter? How do I solve this?

役に立ちましたか?

解決

This is probably just lack of familiarity with Python and the documentation rather than a duck typing issue.

In your particular example, you have to follow the documentation a bit.

In the SMTP.starttls() method, it says:

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

If you follow that link, you will see:

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.

Edit: The keyfile and certfile parameters appear to be filenames (strings). If you then follow the link to Certificates you'll see that the files should be in PEM format.

Thanks to J.F. Sebastian for the tip.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top