TypeError argument should be a Buffer

Posted odejsjhshw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError argument should be a Buffer相关的知识,希望对你有一定的参考价值。

1、错误描述

 

> y.copy(0,10);
TypeError: argument should be a Buffer
    at TypeError (native)
    at repl:1:3
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
>

2、错误原因

 

     buffer.copy(Buffer对象,开始写入处);

     但是这里Buffer对象写成了0

 

3、解决办法

 

> y=Buffer(‘wo ai ni‘);
<Buffer 77 6f 20 61 69 20 6e 69>
> o=Buffer(128);
<Buffer 00 00 00 00 01 00 00 00 80 61 37 02 00 00 00 00 02 00 00 00 00 00 00 00
88 94 43 00 00 00 00 00 01 00 00 00 00 00 00 00 e8 aa 43 00 00 00 00 00 02 00 ..
. >
> o.fill(0);
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..
. >
> o;
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..
. >
> y.copy(0,10);
TypeError: argument should be a Buffer
    at TypeError (native)
    at repl:1:3
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:211:10)
    at REPLServer.Interface._line (readline.js:550:8)
> y.copy(o,10);
8
> o;
<Buffer 00 00 00 00 00 00 00 00 00 00 77 6f 20 61 69 20 6e 69 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..
. >
>


 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow




以上是关于TypeError argument should be a Buffer的主要内容,如果未能解决你的问题,请参考以下文章

如何修复 'ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong type' RaspberryPi

TypeError argument should be a Buffer

Python_异常:TypeError: write() argument must be str, not list

报错处理——TypeError: Dog() takes no arguments

Python_报错:TypeError: Tuple or struct_time argument required

Python错误TypeError: write() argument must be str, not bytes