[英]OSError: [Errno 7] Argument list too long on ubuntu, python calling bitcoind-cli with popen
Running a python script calling bitcoind-cli using popen on ubuntu, on large blocks with many trasactions, when calling getrawtransaction i get the error OSError: [Errno 7] Argument list too long 运行在ubuntu上使用popen调用bitcoind-cli的python脚本,在具有许多trasactions的大块上,当调用getrawtransaction时我得到错误OSError:[Errno 7]参数列表太长
i understand it's a buffer issue between the shell and the python script? 我明白这是shell和python脚本之间的缓冲问题? there's a single argument, i guess it's just a very long one
有一个论点,我想这只是一个很长的论点
need i check something else? 需要我检查别的吗? can i make the buffer larger somehow or should i change the method i interact with bitcoind to RPC?
我可以以某种方式使缓冲区更大或我应该更改我与bitcoind交互到RPC的方法?
tried it on a local and an AWS ubuntu machines 在本地和AWS ubuntu机器上尝试过它
thanks 谢谢
It is your OS limitation eg: 这是您的操作系统限制,例如:
>>> 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
Is it necessary to pass the data on the command line (could you use a pipe/file/socket, etc instead?) in your case? 是否有必要在您的情况下传递命令行上的数据(您可以使用管道/文件/套接字等吗?)? Can you run the command several times with splitted command-line arguments?
您可以使用拆分的命令行参数多次运行该命令吗? See Solving “mv: Argument list too long” .
请参阅解决“mv:参数列表太长” 。
You may get the same error if the passed environment is too large: 如果传递的环境太大,您可能会得到相同的错误:
>>> os.execle('/usr/bin/env', 'env', {'envvar': 'c'*10**9})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/os.py", line 322, in execle
execve(file, args[:-1], env)
OSError: [Errno 7] Argument list too long
The solution is to sanitize the passed environment to avoid unused large envvars. 解决方案是清理传递的环境以避免未使用的大型envvar。
The limits might be hardcoded in the kernel source . 限制可能在内核源代码中是硬编码的 。
Since you are using Python, the best thing you can do is use RPC, such as: 由于您使用的是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)})
where params
is a list of the arguments for the specific method
. 其中
params
是特定method
的参数列表。
You can get rpcuser
and rpcpassword
from the bitcoind configuration file. 您可以从bitcoind配置文件中获取
rpcuser
和rpcpassword
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.