python pycurl验证basic和digest认证的方法
作者:lilongsy 时间:2022-12-17 23:01:15
简介
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()
来源:https://blog.csdn.net/lilongsy/article/details/79086569
标签:python,digest,basic
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python关于维卷积的理解
2022-06-05 07:26:21
![](https://img.aspxhome.com/file/2023/6/121846_0s.png)
处理及遍历XML文档DOM元素属性及方法整理
2024-05-13 10:39:38
Python采用raw_input读取输入值的方法
2021-09-08 03:19:05
window.top[_CACHE]实现多个jsp页面共享一个js对象
2023-07-18 09:25:14
python实现数字炸弹游戏程序
2021-09-29 18:44:24
![](https://img.aspxhome.com/file/2023/0/135020_0s.jpg)
Python图片处理之图片采样处理详解
2021-01-14 12:58:36
![](https://img.aspxhome.com/file/2023/3/109933_0s.png)
Python中用format函数格式化字符串的用法
2022-04-17 03:02:06
AJAX的jQuery实现入门(二)
2008-05-01 13:04:00
JavaScript trim 实现去除字符串首尾指定字符的简单方法
2024-04-26 17:11:30
如何使用Pycharm连接SQL Sever(详细教程)
2024-01-18 22:57:41
![](https://img.aspxhome.com/file/2023/0/113560_0s.png)
Python中np.percentile和df.quantile分位数详解
2021-11-25 17:26:00
![](https://img.aspxhome.com/file/2023/7/97527_0s.png)
{ hide_text } CSS文字隐藏总结报告
2010-06-13 17:19:00
![](https://img.aspxhome.com/file/UploadPic/20106/13/01-30s.jpg)
网站注册那些事儿
2010-01-05 16:49:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/sign_up-46s.jpg)
PHP扩展之kafka安装应用案例详解
2023-09-06 09:53:43
python如何求解两数的最大公约数
2021-01-16 07:38:18
整理Python中常用的conda命令操作
2022-07-17 16:53:33
![](https://img.aspxhome.com/file/2023/6/84986_0s.png)
Python while 循环使用的简单实例
2022-11-16 15:56:18
Python3实现的判断回文链表算法示例
2021-04-10 05:53:25
用Python实现web端用户登录和注册功能的教程
2021-03-03 07:49:09
![](https://img.aspxhome.com/file/2023/3/68323_0s.jpg)
微软Silverlight技术魅力初体验
2008-11-05 11:16:00
![](https://img.aspxhome.com/file/uploadpic/200811/5/47fe8a0e93ec22f6ab6457e1-97.jpg)