小编Bog*_*ota的帖子

OpenSSL 的 Python 部分链命令

我正在尝试使用OpenSSLPython 中的模块进行证书验证。

我有窗口的openssl命令为:

openssl verify -partial_chain -CAfile Intermediate.pem UserCert.pem

你能建议我在 Python 中等效吗?

要求:这需要由OpenSSL或任何 Python3 模块完成。使用os.system将解决问题,但这不会满足要求。

python openssl pyopenssl x509certificate pycrypto

5
推荐指数
0
解决办法
169
查看次数

在Python中使用*删除特定扩展名的文件

我有几个文本文件,名为:

temp1.txt
temp2.txt
temp3.txt
temp4.txt
track.txt
Run Code Online (Sandbox Code Playgroud)

我只想删除以 开头temp和结尾的文件.txt。我尝试使用os.remove("temp*.txt")但出现错误:

The filename, directory name, or volume label syntax is incorrect: 'temp*.txt'
Run Code Online (Sandbox Code Playgroud)

使用 python 3.7 执行此操作的正确方法是什么?

python file delete-file

3
推荐指数
1
解决办法
6375
查看次数

将一本词典的选择性元素添加到另一本词典

我有一个列表:

my_list = ["10", "12", "32", "23"]
Run Code Online (Sandbox Code Playgroud)

和字典:

my_dict = {
    'one': {'index': 0, 'sec_key': 'AB', 'id': '10'},
    'two': {'index': 0, 'sec_key': 'CD', 'id': '12'}, 
    'three': {'index': 0, 'sec_key': 'EF', 'id': '32'}
    }
Run Code Online (Sandbox Code Playgroud)

我想保留一个字典,说 final_dict,只有当 id 出现在 my_list 中时,它才会包含 my_dict 的内容。我试图通过以下方式做到这一点:

sf_dict = dict()

for list_id in my_list:
    for key, value in my_dict.items():
        if list_id == value['id']:
            print("Values : {} {} {}".format(value['index'], value['sec_key'], value['id']))
            sf_dict[key] = key
            sf_dict[key]['index'] = value['index']  
            sf_dict[key]['sec_key'] = value['sec_key']
            sf_dict[key]['id'] = value['id']
        
print(sf_dict)
Run Code Online (Sandbox Code Playgroud)

我能够打印这些值,但是由于以下错误,这些值的分配失败了:

TypeError: 'str' …
Run Code Online (Sandbox Code Playgroud)

python dictionary list python-3.x

0
推荐指数
1
解决办法
47
查看次数