python pycurl驗(yàn)證basic和digest認(rèn)證的方法
簡(jiǎn)介
pycurl類似于Python的urllib,但是pycurl是對(duì)libcurl的封裝,速度更快。
本文使用的是pycurl 7.43.0.1版本。
Apache下配置Basic認(rèn)證
生成basic密碼文件
htpasswd -bc passwd.basic test 123456
開(kāi)啟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認(rèn)證
生成Digest密碼文件
htdigest -c passwd.digest "Digest Encrypt" test
開(kāi)啟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
驗(yàn)證Basic認(rèn)證
# -*- 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()
驗(yàn)證Digest認(rèn)證
# -*- 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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python中argparse模塊及action='store_true'詳解
argparse?是一個(gè)用來(lái)解析命令行參數(shù)的?Python?庫(kù),它是?Python?標(biāo)準(zhǔn)庫(kù)的一部分,這篇文章主要介紹了python中argparse模塊及action=‘store_true‘詳解,需要的朋友可以參考下2023-02-02
解決Python 寫(xiě)文件報(bào)錯(cuò)TypeError的問(wèn)題
這篇文章主要介紹了解決Python 寫(xiě)文件報(bào)錯(cuò)TypeError的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10
python實(shí)現(xiàn)IOU計(jì)算案例
這篇文章主要介紹了python實(shí)現(xiàn)IOU計(jì)算案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
python深度學(xué)習(xí)tensorflow1.0參數(shù)和特征提取
這篇文章主要為大家介紹了python深度學(xué)習(xí)tensorflow1.0參數(shù)和特征提取,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Pandas?多進(jìn)程處理數(shù)據(jù)提高速度
這篇文章主要介紹了Pandas?多進(jìn)程處理數(shù)據(jù)提高速度,Pandas多進(jìn)程的方法,pandarallel?庫(kù),下面具體的測(cè)試方法,需要的朋友可以參考一下,希望對(duì)你的學(xué)習(xí)有所幫助2022-04-04

