python pycurl驗證basic和digest認證的方法
更新時間:2018年05月02日 11:43:58 作者:lilongsy
這篇文章主要介紹了python pycurl驗證basic和digest認證的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
簡介
pycurl類似于Python的urllib,但是pycurl是對libcurl的封裝,速度更快。
本文使用的是pycurl 7.43.0.1版本。
Apache下配置Basic認證
生成basic密碼文件
htpasswd -bc passwd.basic test 123456
開啟mod_auth_basic
LoadModule auth_basic_module modules/mod_auth_basic.so
配置到具體目錄
<Directory "D:/test/basic"> AuthName "Basic Auth Dir" AuthType Basic AuthUserFile conf/passwd.basic require valid-user </Directory>
重啟Apache
Apache下配置Digest認證
生成Digest密碼文件
htdigest -c passwd.digest "Digest Encrypt" test
開啟mod_auth_digest
LoadModule auth_digest_module modules/mod_auth_digest.so
配置到具體目錄
<Directory "D:/test/digest"> AuthType Digest AuthName "Digest Encrypt" # 要與密碼的域一致 AuthDigestProvider file AuthUserFile conf/passwd.digest require valid-user </Directory>
重啟Apache
驗證Basic認證
# -*- coding: utf-8 -*- import pycurl try: from io import BytesIO except ImportError: from StringIO import StringIO as BytesIO buffer = BytesIO() c = pycurl.Curl() c.setopt(c.URL, 'http://test/basic/') c.setopt(c.WRITEDATA, buffer) c.setopt(c.HTTPAUTH, c.HTTPAUTH_BASIC) c.setopt(c.USERNAME, 'test') c.setopt(c.PASSWORD, '123456') c.perform() print('Status: %d' % c.getinfo(c.RESPONSE_CODE)) print(buffer.getvalue()) c.close()
驗證Digest認證
# -*- coding: utf-8 -*- import pycurl try: from io import BytesIO except ImportError: from StringIO import StringIO as BytesIO buffer = BytesIO() c = pycurl.Curl() c.setopt(c.URL, 'http://test/digest/') c.setopt(c.WRITEDATA, buffer) c.setopt(c.HTTPAUTH, c.HTTPAUTH_DIGEST) c.setopt(c.USERNAME, 'test') c.setopt(c.PASSWORD, '123456') c.perform() print('Status: %d' % c.getinfo(c.RESPONSE_CODE)) print(buffer.getvalue()) c.close()
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Python3+Appium安裝及Appium模擬微信登錄方法詳解
這篇文章主要介紹了Python3+Appium安裝及使用方法詳解,需要的朋友可以參考下2021-02-02Python實現(xiàn)信息轟炸工具(再也不怕說不過別人了)
不知道各位小伙伴有沒有遇到過這樣的一個故事,發(fā)現(xiàn)自己直接噴不過,打字速度不夠給力.下面這篇文章就能解決自己噴不過的苦惱,話不多說,上才藝,需要的朋友可以參考下2021-06-06Python進階之多線程的實現(xiàn)方法總結(jié)
在python中主要有兩種實現(xiàn)多線程的方式:通過threading.Thread?()?方法創(chuàng)建線程和通過繼承?threading.Thread?類的繼承重寫run方法,接下來我們分別說一下多線程的兩種實現(xiàn)形式吧2023-04-04