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



目录
相关文章
|
23天前
|
Linux Python
linux上根据运行程序的进程号,查看程序所在的绝对路径。linux查看进程启动的时间
linux上根据运行程序的进程号,查看程序所在的绝对路径。linux查看进程启动的时间
41 2
|
1天前
|
存储 传感器 Linux
STM32微控制器为何不适合运行Linux系统的分析
总的来说,虽然技术上可能存在某些特殊情况下将Linux移植到高端STM32微控制器上的可能性,但从资源、性能、成本和应用场景等多个方面考虑,STM32微控制器不适合运行Linux系统。对于需要运行Linux的应用,更适合选择ARM Cortex-A系列处理器的开发平台。
20 0
|
1月前
|
Ubuntu Linux Shell
在Linux中,如何使用shell脚本判断某个服务是否正在运行?
在Linux中,如何使用shell脚本判断某个服务是否正在运行?
|
1月前
|
算法 Ubuntu Linux
在Linux中,对比apt和yum两种包管理器在不同Linux发行版中应用有何区别?
在Linux中,对比apt和yum两种包管理器在不同Linux发行版中应用有何区别?
|
1月前
|
Linux
在Linux中,如何查看系统上运行的进程?
在Linux中,如何查看系统上运行的进程?
|
19天前
|
存储 Linux 编译器
Linux内核编码风格 【ChatGPT】
Linux内核编码风格 【ChatGPT】
|
20天前
|
Linux
用QEMU模拟运行uboot从SD卡启动Linux
用QEMU模拟运行uboot从SD卡启动Linux
|
29天前
|
Linux Perl
在Linux中,系统目前有许多正在运行的任务,在不重启机器的条件下,有什么方法可以把所有正在运行的进程移除呢?
在Linux中,系统目前有许多正在运行的任务,在不重启机器的条件下,有什么方法可以把所有正在运行的进程移除呢?
|
29天前
|
监控 Linux
在Linux中,有⼀个脚本运行时间可能超过2天,如何做才能使其不间断的运行,而且还可以随时观察脚本运行时的输出信息?
在Linux中,有⼀个脚本运行时间可能超过2天,如何做才能使其不间断的运行,而且还可以随时观察脚本运行时的输出信息?
|
29天前
|
关系型数据库 MySQL Linux
在Linux中,如何检查某项服务是否在运行?
在Linux中,如何检查某项服务是否在运行?