Note that there are some explanatory texts on larger screens.

plurals
  1. POFor user-based and certificate-based authentication, do I want to use urllib, urllib2, or curl?
    primarykey
    data
    text
    <p>A few months ago, I hastily put together a Python program that hit my company's web services API. It worked in three different modes:</p> <p>1) HTTP with no authentication<br> 2) HTTP with user-name and password authentication<br> 3) HTTPS with client certificate authentication<br></p> <p>I got 1) to work with urllib, but ran into problems with 2) and 3). Instead of figuring it out, I ended up calculating the proper command-line parameters to curl, and executing it via os.system().</p> <p>Now I get to re-write this program with the benefit of experience, and I'm not sure if I should use urllib, urllib2, or just stick with curl.</p> <p>The urllib documentation mentions:</p> <pre><code>When performing basic authentication, a FancyURLopener instance calls its prompt_user_passwd() method. The default implementation asks the users for the required information on the controlling terminal. A subclass may override this method to support more appropriate behavior if needed. </code></pre> <p>It also mentions the **x509 argument to urllib.URLopener():</p> <pre><code>Additional keyword parameters, collected in x509, may be used for authentication of the client when using the https: scheme. The keywords key_file and cert_file are supported to provide an SSL key and certificate; both are needed to support client authentication. </code></pre> <p>But urllib2 is one greater than urllib, so naturally I want to use it instead. The urllib2 documentation is full of information about authentication handlers that seem to be designed for 2) above, but makes no mention whatsoever of client certificates.</p> <p>My question: do I want to use urllib, because it appears to support everything I need to achieve? Or should I just stick with curl?</p> <p>Thanks.</p> <p><strong>Edit:</strong> Maybe my question isn't specific enough, so here's another shot. Can I achieve what I want to do with urllib? Or with urllib2? Or am I forced to use curl out of necessity?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload