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. html+css+js(登录页)

    直接上代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  2. Redis 源码简洁剖析 04 - Sorted Set 有序集合

    Sorted Set 是什么 Sorted Set 命令及实现方法 Sorted Set 数据结构 跳表(skiplist) 跳表节点的结构定义 跳表的定义 跳表节点查询 层数设置 跳表插入节点 zs ...

  3. gcc 11.2 在线升级

    环境:centos 7 1.准备开发环境 $ yum groupinstall "Development Tools" $ yum install glibc-static lib ...

  4. PostgreSQL逻辑订阅

    测试环境:PostgreSQL 13.2 1.逻辑订阅简介 由于物理复制只能做到这个集群的复制,不能正对某个对象(表)进行复制,且物理复制的备库只能读,不能写.相反,逻辑订阅同时支持主备库读写,且可以 ...

  5. buid-helper-maven-plugin简单使用

    简介 官方文档 https://www.mojohaus.org/build-helper-maven-plugin/index.html 常用的Goals 名称 说明 build-helper:ad ...

  6. Mysql Json函数创建 (二)

    本节中列出的功能由组件元素组成JSON值. JSON_ARRAY([val[, val] ...]) 计算(可能为空)值列表,并返回包含这些值的JSON数组. mysql> SELECT JSO ...

  7. UIKit绘图演练

    一般使用UIKit给我们提供的绘图来绘制一些文字,图片这些东西.     UIKit给我们提供画图的方法底层也是分为四步.所以也必须在drawRect方法当中去写.     1.如何画文字?      ...

  8. nodejs process uncaughtException

    用过Node一段时间之后,发现那些在事件主循环里碰到的异常会导致Node进程退出.在许多应用场景下,特别是对那些希望永不当机的服务器程序来说,这都是不接受的.uncaughtException事件会提 ...

  9. 《手把手教你》系列技巧篇(六十六)-java+ selenium自动化测试 - 读写excel文件 - 上篇(详细教程)

    1.简介 在自动化测试,有些我们的测试数据是放到excel文件中,尤其是在做数据驱动测试的时候,所以需要懂得如何操作获取excel内的内容.由于java不像python那样有直接操作Excle文件的类 ...

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

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