当前位置: 首页 > news >正文

python--杂识--16--代理密码中包含特殊字符

1 安装nginx

2 centos环境安装

yum install httpd-tools

3 nginx.conf

/etc/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {upstream backend {server 127.0.0.1:80;}server {listen 80;server_name localhost;location / {return 200 'Hello, World!';}}server {listen 514;server_name localhost;auth_basic "Restricted Access";  # 要求输入用户名和密码auth_basic_user_file /etc/nginx/.htpasswd;  # 存储用户名和密码的文件路径location / {proxy_pass http://backend;}}}

4 代理设置密码

测出设置的 test/123abc@

htpasswd -c /etc/nginx/.htpasswd test
New password: 
Re-type new password: 
Adding password for user test

5 启动nginx[代理]

检查配置文件是否正确

/usr/local/nginx/sbin/nginx -t -c /etc/nginx/conf/nginx.conf

启动nginx

/usr/local/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf

6 curl测试

(base) [root@Chasing-Dreams conf]# curl -X GET http://test:123abc%40@localhost:514
Hello, World!

7 python代码测试

import requests
from requests.auth import HTTPBasicAuthurl = 'http://localhost'
username = "test"
password = "123abc@"def special_char(password):tmp_password_list = list()for x in password:if not x.isalnum():x = "%" + hex(ord(x))[2:]tmp_password_list.append(x)password = "".join(tmp_password_list)return passworddef method1():print("===========1=============")proxy = {'http': 'http://localhost:514','https': 'https://localhost:514'}print(proxy)response = requests.get(url, proxies=proxy, auth=HTTPBasicAuth(username, password))print(response.text)def method2():print("===========2=============")print("===========2.1=============")url = "http://%s:%s@localhost:514" % (username, password)   # 代理print(url)response = requests.get(url=url)print(response.text)print("===========2.2=============")password_ = special_char(password)url = "http://%s:%s@localhost:514" % (username, password_)print(url)response = requests.get(url=url)print(response.text)def method3():print("===========3=============")proxy = {'http': 'http://localhost:514','https': 'https://localhost:514'}print(proxy)req = requests.request(method="GET", url=url, proxies=proxy, auth=HTTPBasicAuth(username, password))print(req.text)def method4():print("===========4=============")"""部分代理按该方式处理,使用nginx做代理测试时,没有成功"""global passwordpassword = special_char(password)proxy = {'http': 'http://%s:%s@localhost:514' % (username, password),'https': 'https://%s:%s@localhost:514' % (username, password)}print(proxy)req = requests.request(method="GET", url=url, proxies=proxy)print(req.text)if __name__ == "__main__":method1()method2()method3()method4()"""
运行结果:
(base) [root@Chasing-Dreams test]# python test.py 
===========1=============
{'http': 'http://localhost:514', 'https': 'https://localhost:514'}
Hello, World!
===========2=============
===========2.1=============
http://test:123abc@@localhost:514
Hello, World!
===========2.2=============
http://test:123abc%40@localhost:514
Hello, World!
===========3=============
{'http': 'http://localhost:514', 'https': 'https://localhost:514'}
Hello, World!
===========4=============
{'http': 'http://test:123abc%40@localhost:514', 'https': 'https://test:123abc%40@localhost:514'}
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.20.2</center>
</body>
</html>
"""
http://www.lryc.cn/news/293923.html

相关文章:

  • 【Git】05 分离头指针
  • 【Tomcat与网络9】提高Tomcat启动速度的八大措施
  • 蓝桥杯嵌入式第七届真题(完成) STM32G431
  • 如何降低视频RTSP解码延迟
  • 【Golang】自定义logrus日志保存为日志文件
  • 【大厂AI课学习笔记】1.4 算法的进步(4)关于李飞飞团队的ImageNet
  • 【Linux笔记】缓冲区的概念到标准库的模拟实现
  • 【前端收藏】前端小作文-前端八股文知识总结(超万字超详细)持续更新
  • GNSS模块的惯导技术:引领定位科技的前沿
  • Flutter 和 Android原生(Activity、Fragment)相互跳转、传参
  • Kubernetes基础(十一)-CNI网络插件用法和对比
  • yo!这里是单例模式相关介绍
  • 2023年上-未来几年我要做什么
  • 智能汽车竞赛摄像头处理(3)——动态阈值二值化(大津法)
  • BGP协议
  • 一个完整工作流管理系统的组成部分
  • 鱼和熊掌如何兼得?一文解析RDS数据库存储架构升级
  • 中科大计网学习记录笔记(五):协议层次和服务模型
  • 同构异机迁移方案2_目标服务器仅安装数据库软件scp物理文件
  • 华为机考入门python3--(6)牛客6-质数因子
  • 11月最新版付费进群源码自动定位+开源
  • Python算法题集_旋转图像
  • [ChatGPT们】ChatGPT 如何辅助编程初探
  • 深入Spring MVC的工作流程
  • 我的数据结构c(给自己用的)
  • 使用Arcgis对欧洲雷达高分辨率降水数据重投影
  • [Python] scikit-learn中数据集模块介绍和使用案例
  • Qt-互斥量-临界区-QMutex-QMutexLocker-QReadWriteLock
  • 《PCI Express体系结构导读》随记 —— 第II篇 第4章 PCIe总线概述(6)
  • uniapp 高德地图显示