Myluzh Blog

Strive to become a dream architect.

python使用urllib3库实现HTTP请求

2020-4-15 myluzh Python

使用urllib3库生成一个完整的http请求,请求应该包含请求方式、请求连接、请求头、超时时间和重试次数。通过request方法可以创建一个请求,该方法返回http响应对象,语法如下: urllib3.request(method,url,headers,timeout) 参数 说明 method 接收string。表示请求类型,例如GET,无默认值 url 接收string。表示请求的URL,无默认值 headers 接收dict。请求头,默认为None data 接收dict。POST提交的数据 timeout 接收float。设置请求超时时间 ...

阅读全文>>

标签: python urllib3

评论(0) (773)

python3对字符串进行md5加密

2020-4-11 myluzh Python

# 由于MD5模块在python3中被移除 # 在python3中使用hashlib模块进行md5操作 import hashlib # 输入待加密字符串 str = input('Please enter the string to be MD5 encrypted:\n') # 创建md5对象 m = hashlib.md5() # Tips # 此处必须encode # 若写法为m.update(str) 报错为: Unicode-objects must be encoded before hashing # 因为python3里默认的str是unicode # 或者 b = bytes(str, encoding='utf-8'),作用相同,都是encode为bytes b = str.encode(encoding='utf-8') m.update(b) str_md5 = m.hexdigest() #输出md5加密后的值 print('After MD5 encryption:\n' + str_md5)

阅读全文>>

标签: python md5

评论(0) (556)

python更换国内的pip源

2020-4-8 myluzh Python

0x01 国内pip源地址 阿里云 http://mirrors.aliyun.com/pypi/simple/ 豆瓣 http://pypi.douban.com/simple/ 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 0x02 临时使用pip源 在使用pip时候,后面加上参数-i 镜像地址,例如: pip3 install pygame -i http://mirrors.aliyun.com/pypi/simple/ 0x03 永久更换pip源 1.Linux下,修改 ~/.pip/pip.conf 没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹。内容如下: [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn 2.window...

阅读全文>>

标签: python pip

评论(0) (660)

python base64加解密脚本(可变换码表)

2020-2-23 myluzh Python

# coding:utf-8 s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" #s = "vwxrstuopq34567ABCDEFGHIJyz012PQRSTKLMNOZabcdUVWXYefghijklmn89+/" def My_base64_encode(inputs): # 将字符串转化为2进制 bin_str = [] for i in inputs: x = str(bin(ord(i))).replace('0b', '') bin_str.append('{:0>8}'.format(x)) #print(bin_str) # 输出的字符串 outputs = "" # 不够三倍数,需补齐的次数 nums = 0 while bin_str: #每次取三个字符的二进制 temp_list = bin_str[:3] if(len(temp_list) != 3): nums = 3 - len(temp_list) ...

阅读全文>>

标签: python 加密 base64 解密 码表

评论(0) (5032)