python pycurl驗(yàn)證basic和digest認(rèn)證的方法
簡(jiǎn)介
pycurl類(lèi)似于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)文章
Python3+Appium安裝及Appium模擬微信登錄方法詳解
這篇文章主要介紹了Python3+Appium安裝及使用方法詳解,需要的朋友可以參考下2021-02-02python實(shí)現(xiàn)多線(xiàn)程端口掃描
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)多線(xiàn)程端口掃描,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08淺談python 導(dǎo)入模塊和解決文件句柄找不到問(wèn)題
今天小編就為大家分享一篇淺談python 導(dǎo)入模塊和解決文件句柄找不到問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12Python實(shí)現(xiàn)信息轟炸工具(再也不怕說(shuō)不過(guò)別人了)
不知道各位小伙伴有沒(méi)有遇到過(guò)這樣的一個(gè)故事,發(fā)現(xiàn)自己直接噴不過(guò),打字速度不夠給力.下面這篇文章就能解決自己噴不過(guò)的苦惱,話(huà)不多說(shuō),上才藝,需要的朋友可以參考下2021-06-06Python進(jìn)階之多線(xiàn)程的實(shí)現(xiàn)方法總結(jié)
在python中主要有兩種實(shí)現(xiàn)多線(xiàn)程的方式:通過(guò)threading.Thread?()?方法創(chuàng)建線(xiàn)程和通過(guò)繼承?threading.Thread?類(lèi)的繼承重寫(xiě)run方法,接下來(lái)我們分別說(shuō)一下多線(xiàn)程的兩種實(shí)現(xiàn)形式吧2023-04-04Python使用Matplotlib繪制甘特圖的實(shí)踐
甘特圖已經(jīng)發(fā)展成項(xiàng)目規(guī)劃和跟蹤的必備工具,本文主要介紹了Python使用Matplotlib繪制甘特圖的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12