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 ...
随机推荐
- Object的rest和spread方法
//将多个对象合并到一个对象里 const input = { a: 1, b: 2 } const test = { d: 5 } const output = { ...input, ...tes ...
- C++继承、多态与虚表
继承 继承的一般形式 子类继承父类,是全盘继承,将父类所有的东西都继承给子类,除了父类的生死,就是父类的构造和析构是不能继承的. 继承的访问权限从两方面看: 1.对象:对象只能直接访问类中公有方法和成 ...
- 吴裕雄 python 机器学习——半监督学习LabelSpreading模型
import numpy as np import matplotlib.pyplot as plt from sklearn import metrics from sklearn import d ...
- blog主题——马路
blog主题,存储一下 css /************************************************** 第一部分:所有的模板都使用的公共样式.公告样式是为了更好的向前 ...
- Unity 鼠标旋转物体360展示
PC端 using UnityEngine; using System.Collections; public class DragRound : MonoBehaviour { public Tra ...
- putty上传下载文件
一,需要pscp.exe,习惯上和Putty.exe文件放在一起. 首先需要保证在命令行下可以访问到pscp.exe.可以通过配置Windows的环境变量Path,或者直接通过命令行访问到pscp.e ...
- 「JSOI2015」串分割
「JSOI2015」串分割 传送门 首先我们会有一个贪心的想法:分得越均匀越好,因为长的绝对比短的大. 那么对于最均匀的情况,也就是 \(k | n\) 的情况,我们肯定是通过枚举第一次分割的位置,然 ...
- Laravel 解决在ajax 请求下不能保存session的问题
Laravel 解决在ajax 请求下不能保存session的问题 \Session::put('isLogin',true); // 你要保存的session key \Session::put(' ...
- liux 命令行
查找文件 () find / -name httpd.conf #在根目录下查找文件httpd.conf,表示在整个硬盘查找 () find /etc -name httpd.conf #在/etc目 ...
- linux 配置IPSAN存储
一 SAN存储 1.1 SAN存储介绍 存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通 ...