OSError:[Errno 7]ubuntu上的参数列表太长,python用popen调用bitcindcli

2024-10-02 20:33:23 发布

您现在位置:Python中文网/ 问答频道 /正文

在ubuntu上运行一个python脚本,使用popen调用bitcoind cli,在有很多事务的大块上,当调用getrawtransaction时,我得到错误消息:OSError:[Errno 7]参数列表太长

我知道这是shell和python脚本之间的缓冲区问题? 只有一个论点,我想这只是一个很长的论点

我需要检查一下别的吗? 我可以让缓冲区变大吗?还是应该将我与比特币交互的方法改为RPC?在

在本地的机器上试过了

谢谢


Tags: 脚本消息参数cliubuntu错误事务缓冲区
2条回答

例如,您的操作系统限制:

>>> import os
>>> os.execl('/bin/ls', 'ls', 'c'*10**7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/os.py", line 314, in execl
    execv(file, args)
OSError: [Errno 7] Argument list too long

是否有必要在命令行上传递数据(您是否可以使用管道/文件/套接字等)对你来说呢?你能用分开的命令行参数多次运行这个命令吗?见Solving “mv: Argument list too long”。在

如果传递的环境太大,则可能会出现相同的错误:

^{pr2}$

解决方案是清理传递的环境,以避免未使用的大型环境变量。在

The limits might be hardcoded in the kernel source。在

由于您使用的是Python,所以最好的做法是使用RPC,例如:

import base64
import requests

response = requests.post(
    bitcoind_url, 
    data=json.dumps(
        {
            'method': method,
            'params': params,
            'jsonrpc': '2.0',
            'id': 0,
        }
    ), 
    headers={'content-type': 'application/json', 'Authorization': b'Basic ' + base64.b64encode(rpcuser + b':' + rpcpassword)})

其中params是特定method的参数列表。在

您可以从比特币配置文件中获得rpcuser和{}。在

相关问题 更多 >