幾個月前,我匆忙地把一個Python程序放到了我公司的Web服務API上。它的工作在三種不同模式:對於基於用戶和基於證書的身份驗證,我想使用urllib,urllib2還是curl?
1)HTTP沒有認證
2)HTTP使用用戶名和密碼驗證
3)HTTPS使用客戶證書驗證
我1)一起工作urllib,但遇到了2)和3)的問題。我沒有搞清楚,而是計算了合適的命令行參數來捲曲,並通過os.system()來執行它。
現在,我得到這個程序有經驗的利益重新寫,我不知道我是否應該使用的urllib,urllib2的,或者只是堅持捲曲。
的urllib的文檔中提到:
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.
它還提到** X509參數urllib.URLopener():
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.
但是urllib2的是一個比urllib的更大,所以自然想改爲使用它。 urllib2文檔充滿了關於認證處理程序的信息,這些信息似乎是爲上述2)設計的,但沒有提及任何客戶端證書。
我的問題:我想使用urllib的,因爲它似乎在支持我需要的一切來實現?或者我應該堅持捲曲?
謝謝。
編輯:也許我的問題不夠具體,所以這裏是另一個鏡頭。我可以用urllib實現我想要做的嗎?或者與urllib2?還是我不得不使用捲毛?
我並不想建立一個網頁瀏覽器;我只是想用各種形式的認證來使用WSDL API。機械化網頁根本不討論認證。 – 2010-10-22 12:23:01