如何以及使用哪個python庫可以使用user:password或令牌創建httprequest(https)?帶有令牌的python http請求
基本上相當於curl -u user:pwd https://www.mysite.com/
謝謝
如何以及使用哪個python庫可以使用user:password或令牌創建httprequest(https)?帶有令牌的python http請求
基本上相當於curl -u user:pwd https://www.mysite.com/
謝謝
類urllib2.HTTPSHandler 來處理HTTPS URL的開口A類。
21.6.7。 HTTPPasswordMgr對象 這些方法在HTTPPasswordMgr和HTTPPasswordMgrWithDefaultRealm對象上可用。
HTTPPasswordMgr.add_password(realm,uri,user,passwd) uri可以是單個URI,也可以是一系列URI。 realm,user和passwd必須是字符串。這將導致(user,passwd)在給定realm的任何給定URI的超級URI的身份驗證時被用作身份驗證令牌。 HTTPPasswordMgr.find_user_password(realm,authuri) 獲取給定領域和URI(如果有的話)的用戶/密碼。如果沒有匹配的用戶/密碼,此方法將返回(無,無)。
對於HTTPPasswordMgrWithDefaultRealm對象,如果給定的領域沒有匹配的用戶/密碼,則將搜索領域None。
查看我們的urllib2
。底部的例子可能會引起人們的興趣。
如果你需要線程安全的要求,使用pycurl
(Python接口捲曲):
import pycurl
from StringIO import StringIO
response_buffer = StringIO()
curl = pycurl.Curl()
curl.setopt(curl.URL, "https://www.yoursite.com/")
# Setup the base HTTP Authentication.
curl.setopt(curl.USERPWD, '%s:%s' % ('youruser', 'yourpassword'))
curl.setopt(curl.WRITEFUNCTION, response_buffer.write)
curl.perform()
curl.close()
response_value = response_buffer.getvalue()
否則,使用urllib2
(詳情參見其他響應),因爲它是內置和界面更清潔。
謝謝...這就是它 – aschmid00 2010-07-28 19:06:24