SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xd0 in position 2: invalid continuation byte
[root@hostuser src]# python3 subprocess_popen.py
File "subprocess_popen.py", line 23
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xd0 in position 2: invalid continuation byte
#!/usr/bin/python3
# coding=gbk
import os
import sys
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
import subprocess
from src import logutils def run():
log=logutils.logger("app",rootstdout=True,handlerList=['I','E'])
str_shell='df -m && netstat -ntlp'
sub=subprocess.Popen(args=str_shell,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,
stderr=subprocess.PIPE,universal_newlines=True)
out,err=sub.communicate()
#res=sub.stdout.readlines()
#log.info(res) if sub.returncode == 0:
#log.info("returncode is 0,执行输出正常")
if out:
log.info("执行输出正常")
log.info(out)
if err:
log.error("出现异常")
log.error(err,exc_info=True)
else:
if sub.returncode == 1:
log.error("执行shell对象结果有空")
else:
raise subprocess.CalledProcessError(sub.returncode, str_shell) if __name__ == '__main__':
run()
起初# -*- coding:utf-8 -*- 再运行还是报错,加上#coding=gbk问题完美解决
关于subprocess.returncode:
我总结的有以下几种情况
returncode=0 表示执行成功
returncode=1,表示执行结果为空
returncode=127 表示语句为空串
returncode=17 表示找不到表
returncode=64 表示缺失关键字
returncode=41 表示查询的字段不存在
!
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xd0 in position 2: invalid continuation byte的更多相关文章
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 140: invalid continuation byte
web阅片系统,遇到dicom文件在文件夹不能正常读取的问题.解决方法如下: def rep7(request): file_path = os.path.dirname(__file__) + re ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
用pandas打开csv文件可能会出现这种情况,原因可能是excel自己新建一个*.csv文件时候容易出错.进入文件另存为,然后选择csv文件即可.
- rosbag遍历数据出错:(unicode error) 'utf-8' codec can't decode byte 0xcd in position 31: invalid continuation byte
主题: 前言 针对ros系统记录的bag文件,可以使用python的rosbag包,按照不同起止时间和topic进行提取. 然而,有的topic可以使用rosbag读取,但是不能遍历,存在解码错误.原 ...
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xce in position 47: invalid continuation byte
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 22: invalid continuation byte
在使用python读取文本文件,一般会这样写: # -*- coding:utf-8 -*- f = open("train.txt", "r", encodi ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 52: invalid continuation byte
代码: df_w = pd.read_table( r'C:\Users\lab\Desktop\web_list_n.txt', sep=',', header=None) 当我用pandas的re ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 99: invalid continuation byte
Traceback (most recent call last): File "/Users/c2apple/PycharmProjects/easyToPython/fileMethod ...
- 【安装Python环境】之安装Selenium2时报UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 12: invalid continuation byte问题
问题描述: windows8.1系统,Python3环境安装Selenium2时报错,错误如下: ..... ..... File "F:\软件\python3.6.1\lib\site-p ...
- python3 报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 201: invalid continuation byte
代码: # -*- coding:utf-8 -*- from urllib import request resp = request.urlopen('http://www.xxx.com') p ...
随机推荐
- MS Sqlserver删除字段最后的多余字符
存在这样一些数据 ,,,,dga bc,,aaaa,,,,,,,,dga bc,,aaaa,,,,,,,dga bc,,aaaa,,,,,,,dga bc,,aaaa,,,,,, 需要将最后多余的逗号 ...
- 关于进程,I/O模型的文章
PHP类 http://rango.swoole.com/archives/508 Node https://github.com/DoubleSpout/threadAndPackage
- c++调用自己编写的静态库(通过eclipse)
转:https://blog.csdn.net/hao5335156/article/details/80282829 参考:https://blog.csdn.net/u012707739/arti ...
- 吴裕雄 python 机器学习——半监督学习LabelSpreading模型
import numpy as np import matplotlib.pyplot as plt from sklearn import metrics from sklearn import d ...
- 吴裕雄 python 机器学习——半监督学习标准迭代式标记传播算法LabelPropagation模型
import numpy as np import matplotlib.pyplot as plt from sklearn import metrics from sklearn import d ...
- 67课 for循环1-为什么需要for循环
# include <stdio.h> int main (void) { int i; ;.//sum代表和的意思 ; i<=; ++i)//第八行代码 sum = sum + i ...
- C# 之 代码实现延时
Task.Delay();异步实现 using System;using System.Threading.Tasks; namespace csharpYS{ class Program { sta ...
- redis环境搭建学习笔记
学习环境为windows.java环境 一.学习教程: 1.菜鸟教程:http://www.runoob.com/redis/redis-tutorial.html 2.redis中文网:http:/ ...
- C语言报错:“gets”: 找不到标识符。解决方法
C语言报错:“gets”: 找不到标识符. 把“gets”改成“gets_s”即可.
- ajax传map,后端接收并解析
前端let map = new Map(); map.set(1, 1); map.set(2, 2); map.set(3, 3); //map转obj let obj= Object.create ...