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

  1. pyinstaller设置图标出现“struct.error: unpack requires a buffer of 16 bytes”

    pyinstaller设置图标出现"struct.error: unpack requires a buffer of 16 bytes" 直接用png图片改后缀名为ico,然后p ...

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

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

  4. error: unpack failed: error Missing tree

    最近新建一个仓库,push时遇到如下问题,试了好多方法,最后在stackoverflow上找到解决办法了,可是在开始时就试过这方法,但不成.至于为嘛出现的这种错误,还是不明白原因. git.exe p ...

  5. gerrit代码审核工具之“error unpack failed error Missing unknown”错误解决思路

    使用gerrit代码审核工具时遇到error: unpack failed: error Missing unknown d6d7c89bd1d77f44c5c8e99437aaffbfc0684e7 ...

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

  7. innobackupex: Error: --decompress requires qpress

    数据库版本:5.6.16​系统版本:cenos 6.5​​通过percona-xtranbackup恢复数据库报错(软件版本:percona-xtrabackup-2.1.9-744.rhel6.x8 ...

  8. Cannot enlarge string buffer containing XX bytes by XX more bytes

    在ELK的数据库报警系统中,发现有台机器报出了下面的错误: 2018-12-04 18:55:26.842 CST,"XXX","XXX",21106,&quo ...

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

随机推荐

  1. K8S访问机制

    pod -> endpoint -> service -> namespace -> svc.cluster.local .....在 a 名称空间,访问 b 名称空间的 b1 ...

  2. django学习总结1

    ## 内容回顾 #### 1.所有的命令 ##### 下载安装 ​ pip install django==1.11.20 - i 源 ##### 创建项目 ​ django-admin startp ...

  3. Python json库中load、loads、dump、dumps的区别与用法

    1 json.loads() 将json格式的数据转化为字典类型 data_json = '{"msg": "登录成功", "code": ...

  4. 深入Windows APC

      本篇原文为 Depths of Windows APC ,如果有良好的英文基础,可以点击该链接进行阅读.本文为我个人:寂静的羽夏(wingsummer) 中文翻译,非机翻,著作权归原作者 Rbmm ...

  5. c#序列化感悟(重点讲讲二进制序列化)

    序列化是一种通过将对象转化为字节流,从而达到储存对象,或者将对象传输到内存,数据库或文件的一个过程,主要用途是保存对象的状态(包括对象的数据),方便对对象的重建,反之读取就是反序列化. 三种序列化类型 ...

  6. Nginx实现跨域配置详解

    主要给大家介绍了关于Nginx跨域使用字体文件的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍: 问题描述 今天在使用子域名访问根域名的CSS时,发现字体无法显示,在确保CSS和Font字 ...

  7. eclipse快捷键 包括查找类、方法、变量

    [Ct rl+T] 搜索当前接口的实现类 1. [ALT +/]    此快捷键为用户编辑的好帮手,能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类.方法和属性的名字时,多体验一下[ ...

  8. nginx的优化和防盗链

    nginx的优化和防盗链 目录 nginx的优化和防盗链 一.nginx的优化 1. 隐藏版本号 (1)隐藏版本号的原因 (2)查看版本号的方法 (3)隐藏方法一:修改配置文件 (4)隐藏方法二:修改 ...

  9. 我们一起来学Shell - 初识shell

    文章目录 Shell 的分类 `bash` `csh` `ksh` `tcsh` `sh` `nologin` `zsh` Shell 能做什么 bash 环境变量文件 `/etc/profile` ...

  10. 关于maven依赖中的scope的作用和用法

    举例如下: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>s ...