Linux yum 运行时提示编码问题错误

简介: Linux yum 运行时提示编码问题错误
  1. 报错:
    UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  2. 解决:

这个报错是编码问题导致的

在文件头加上

# -*- coding:utf-8 -*-

对需要比较的中文字符变量如:

label = label.decode('utf-8')


具体实例:

  1. 问题展示:
[root@localhost .pyenv]# yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
/usr/lib/python2.7/site-packages/yum/misc.py:133: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  return lambda s: s.lower() == pat
  1. 问题解决:
1 # -*- coding:utf-8 -*-
2 #! /usr/bin/python -tt
3 """
4 Assorted utility functions for yum.
5 """
6
7 import types
8 import os
9 import sys
10 import os.path
11 from cStringIO import StringIO
12 import base64
13 import binascii
14 import struct
15 import re
16 import errno
17 import Errors
18 import constants
19 import pgpmsg
20 import tempfile
21 import glob
22 import pwd
23 import fnmatch
24 import bz2
25 import gzip
26 import shutil
27 import urllib
28 import string
......
124 def compile_pattern(pat, ignore_case=False):
125     """ Compile shell wildcards, return a 'match' function. """
126     if re_glob(pat):
127         try:
128             flags = ignore_case and re.I or 0
129             return re.compile(fnmatch.translate(pat), flags).match
130         except re.error:
131             pass # fall back to exact match
132     if ignore_case:
133         pat = pat.lower()
134         return lambda s: s.lower() == pat.decode('utf-8')
135     return lambda s: s == pat
  1. 再次测试:
[root@localhost .pyenv]# yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
[root@localhost .pyenv]# yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost .pyenv]# 


分享一个有趣的 学习链接:https://xxetb.xet.tech/s/HY8za


目录
相关文章
|
14天前
|
缓存 Linux
【Linux基础】 常用 yum 命令
yum是Yellowdog Updater, Modified的简称,旨在自动化地升级、安装/移除 RPM 安装包。它通过收集rpm包的相关信息,检查依赖性,并提示用户解决依赖问题,从而简化了Linux系统中软件包的管理。
40 10
|
14天前
|
监控 数据挖掘 大数据
Linux中的nohup命令:让你的任务在后台持久运行
**Linux的`nohup`命令让任务在后台持续运行,即使终端关闭。它创建不受终端影响的新进程,常用于长时间任务,如数据处理。`nohup`将输出重定向至`nohup.out`,可使用`-p`选项避免此行为。示例:`nohup ./script.sh > output.log 2>&1 &`。记得检查输出、重定向、记录命令、监控任务并使用日志管理工具。**
|
2天前
|
关系型数据库 MySQL Linux
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
|
2天前
|
Ubuntu Linux
Linux软件安装-Linux系统靠yum命令安装软件,yum命令是一个RPM包软件管理器,用于自动化安装配置Linux软件,.rpm是Linux包下的软件,yum install下载 wget re
Linux软件安装-Linux系统靠yum命令安装软件,yum命令是一个RPM包软件管理器,用于自动化安装配置Linux软件,.rpm是Linux包下的软件,yum install下载 wget re
|
3天前
|
Linux 调度
Linux |使用“at”命令在指定时间运行任务
Linux |使用“at”命令在指定时间运行任务
7 0
|
10天前
|
监控 网络协议 关系型数据库
如何在Linux中查看正在运行的进程以及过滤特定端口和进程名称
如何在Linux中查看正在运行的进程以及过滤特定端口和进程名称
11 0
|
12天前
|
缓存 人工智能 Linux
【Linux】--- 详解Linux软件包管理器yum和编辑器vim
【Linux】--- 详解Linux软件包管理器yum和编辑器vim
22 0
|
2月前
|
缓存
yum 如何设置可以将安装的rpm包都缓存下来
【4月更文挑战第17天】yum 如何设置可以将安装的rpm包都缓存下来
229 0
|
19天前
yum 可以安装rpm包
【6月更文挑战第18天】yum 可以安装rpm包
77 0
|
10天前
|
缓存
创建本地yum源并安装tree命令(openEuler-20.03-LTS-SP3)
创建本地yum源并安装tree命令(openEuler-20.03-LTS-SP3)
23 1