struct.error: unpack requires a buffer of 26 bytes
with open('Test.bmp', 'rb') as f:
s = f.read(30)
#利用struct提取信息
struct.unpack('<ccIIIIIHH',s)
#报错
#struct.error: unpack requires a buffer of 26 bytes
原因是,unpack函数的第一个参数中少写了一个I(4字节),导致处理的数据大小为26Bytes,而s为30Bytes。
修改为:
struct.unpack('<ccIIIIIIHH',s)
(b'B', b'M', 33510, 0, 54, 40, 109, 102, 1, 24)
总结:struct.unpack将二进制数据转化为其他数据时,第一个参数表示处理指令,其中处理的数据大小必须与第二个参数完全相等。
struct.error: unpack requires a buffer of 26 bytes的更多相关文章
- pyinstaller设置图标出现“struct.error: unpack requires a buffer of 16 bytes”
pyinstaller设置图标出现"struct.error: unpack requires a buffer of 16 bytes" 直接用png图片改后缀名为ico,然后p ...
- ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!
通过ansible执行远程命令时报如下异常: Error: ansible requires the stdlib json or simplejson module, neither was fou ...
- Git review :error: unpack failed: error Missing tree
环境 git version 1.9.1 Gerrit Code Review (2.11.3) 1 2 现象 修改后调用 git review可以提交到Gerrit上,然后只要一用 git comm ...
- error: unpack failed: error Missing tree
最近新建一个仓库,push时遇到如下问题,试了好多方法,最后在stackoverflow上找到解决办法了,可是在开始时就试过这方法,但不成.至于为嘛出现的这种错误,还是不明白原因. git.exe p ...
- gerrit代码审核工具之“error unpack failed error Missing unknown”错误解决思路
使用gerrit代码审核工具时遇到error: unpack failed: error Missing unknown d6d7c89bd1d77f44c5c8e99437aaffbfc0684e7 ...
- python——unpack问题 ocr_recognize timeout , exception:unpack requires a string argument of length 46
rObjBuff = "".join(unpack('=%ds' % ObjLen, recv_buf[6+i*ObjLen:6+(i+1)*ObjLen]))score, bbo ...
- innobackupex: Error: --decompress requires qpress
数据库版本:5.6.16系统版本:cenos 6.5通过percona-xtranbackup恢复数据库报错(软件版本:percona-xtrabackup-2.1.9-744.rhel6.x8 ...
- Cannot enlarge string buffer containing XX bytes by XX more bytes
在ELK的数据库报警系统中,发现有台机器报出了下面的错误: 2018-12-04 18:55:26.842 CST,"XXX","XXX",21106,&quo ...
- String field contains invalid UTF-8 data when serializing a protocol buffer. Use the 'bytes' type if you intend to send raw bytes.
[libprotobuf ERROR google/protobuf/wire_format.cc:1053] String field contains invalid UTF-8 data whe ...
随机推荐
- python3 类的学习
# -*-coding:utf-8-*- # 定义类是通过class关键字,class后面紧接着是类名,即Student,类名通常是大写开头的单词,紧接着是(object),表示该类是从哪个类继承下来 ...
- CPU飙升排查
怎么排查CPU飙升 线上有些系统,本来跑的好好的,突然有一天就会出现报警,CPU使用率飙升,然后重启之后就好了.例如,多线程操作一个线程不安全的list往往就会出现这种现象.那么怎么定位到具体的代码范 ...
- python类和函数
#/usr/bin/python #coding=utf-8 class Car(): def __init__(self,name,year): self.name = name self.year ...
- Vue之 watch、computed、filter之间的区别与使用场景
computed 计算属性: 当页面中需要使用大量的表达式处理数据时,为了页面维护更加简单,所以使用 计算属性 来出来复杂的逻辑运算 watch 侦听器 当需要在数据变化时执行异步或开销较大的操作时 ...
- Vue 之 vue-cropper 组件实现头像裁剪功能
组件与api地址: npm地址地址:https://www.npmjs.com/package/vue-cropper/v/0.4.7 GitHub地址:https://github.com/xyxi ...
- Sleep_Yield_Join
名称解释 Sleep:意思就是睡眠,当前线程暂停一段时间让给别的线程去运行;Sleep是怎么复活的?由你的睡眠时间而定,等睡眠到规定的时间自动复活. Yield:就是当前线程正在执行的时候停止下来进入 ...
- Javascript疑问【长期更新】
1.插入 Javacript 的正确位置是? 答:<body> 部分和 <head> 部分均可. 2.外部脚本必须包含 <script> 标签吗? 答:外部脚本不能 ...
- ANT中的copy和move标签
Copy标签 该标签用于文件或文件集的拷贝,其属性如下: file 表示源文件. tofile 表示目标文件. todir 表示目标目录. overwrite 表示指定是否覆盖目标文件,默认值是不覆盖 ...
- Linux-标准输入标准输出
标准输入(代码为0) 标准输出(代码为1) 标准错误输出(代码为2) 将标准输出重定向到一个文件 find /etc -name fileA >list 等同于 find /etc -name ...
- 云端iclound使用-陈棚
使用NSmetadataQuery查询文档,增加,删除,编辑 界面设计完成后效果如图: 程序清单:FKDiary.h @interface FKDiary : UIDocument @property ...