[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的更多相关文章

  1. 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 ...

  2. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte

    用pandas打开csv文件可能会出现这种情况,原因可能是excel自己新建一个*.csv文件时候容易出错.进入文件另存为,然后选择csv文件即可.

  3. rosbag遍历数据出错:(unicode error) 'utf-8' codec can't decode byte 0xcd in position 31: invalid continuation byte

    主题: 前言 针对ros系统记录的bag文件,可以使用python的rosbag包,按照不同起止时间和topic进行提取. 然而,有的topic可以使用rosbag读取,但是不能遍历,存在解码错误.原 ...

  4. UnicodeDecodeError: 'utf8' codec can't decode byte 0xce in position 47: invalid continuation byte

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 【安装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 ...

  9. 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 ...

随机推荐

  1. js的undefined和null

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 7_2 最大乘积(UVa11059)<枚举连续子序列>

    给一个数字集合{ S1,S2,…,Sn },请从这个数字集合里找出一段连续数字,使他们的乘积是最大的.以Case 1为例子,2 x 4 = 8为这个集合的最大乘积:而Case 2则为2 x 5 x(– ...

  3. 排查 k8s 集群 master 节点无法正常工作的问题

    搭建的是 k8s 高可用集群,用了 3 台 master 节点,2 台 master 节点宕机后,仅剩的 1 台无法正常工作. 运行 kubectl get nodes 命令出现下面的错误 The c ...

  4. 计算几何-Ang-Rad-Vector

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 旋转,跳跃,梦境 ...

  5. @AliasFor 原理

      用法: import org.springframework.core.annotation.AliasFor; import java.lang.annotation.*; @Target(El ...

  6. AcWing 867. 分解质因数

    #include <iostream> #include <algorithm> using namespace std; void divide(int x) { ; i & ...

  7. OO博客作业-《JML之卷》

    OO第三单元小结 一.JML语言理论基础以及应用工具链情况梳理 一句话来说,JML就是用于对JAVA程序设计逻辑的预先约定的一种语言,以便正确严格高效地完成程序以及展开测试,这在不能容忍细微错误的工程 ...

  8. 联合查询:union

    1.联合查询:union 1.1 作用:将多条select语句的结果,合并到一起,称之为联合操作. 1.2 语法:( ) union ( ); 例子:(select name from info_or ...

  9. Dart语言学习(八) dynamic

    dynamic 表示是动态的,数据类型是指任意类型 var a; a = ; a = "Dart"; print(a); dynamic b = ; b = "JavaS ...

  10. jsTree的checkbox默认选中和隐藏

    jstree复选框自定义显示隐藏和初始化默认选中 首先需要配置 Checkbox plugin "plugins" : ['checkbox'] 设置默认选中状态(checkbox ...