简体   繁体   English

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

[英]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配置文件中获取rpcuserrpcpassword

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError: [Errno 7] 参数列表太长:&#39;php&#39; - Python 3.6 - OSError: [Errno 7] Argument list too long: 'php' - Python 3.6 Linux OS中的Python OSError no 7(参数列表太长) - Python OSError no 7 (Argument list too long ) in linux OSError:[Errno 36]使用Popen时文件名太长-Python - OSError: [Errno 36] File name too long while using Popen - Python 间歇性“OSError: [Errno 7] Argument list too long”和短命令(~125 个字符) - Intermittent “OSError: [Errno 7] Argument list too long” with short command (~125 chars) 为什么我收到 OSError: [Errno 7] 参数列表太长:b&#39;/usr/local/bin/git&#39;? - Why I`m getting OSError: [Errno 7] Argument list too long: b'/usr/local/bin/git'? subprocess.Popen参数列表过长 - subprocess.Popen Argument list is too long OSError:[Errno 24]太多打开的文件python,ubuntu - OSError: [Errno 24] Too many open files python , ubuntu OSError:[Errno 63] JSON 文件(python)中的文件名太长 - OSError: [Errno 63] File name too long in JSON FILE (python) 为什么在使用mrjob v0.4.4时,[Errno 7]参数列表过长且OSError:[Errno 24]打开的文件太多? - Why am I getting [Errno 7] Argument list too long and OSError: [Errno 24] Too many open files when using mrjob v0.4.4? OSError:[Errno 36]文件名太长: - OSError: [Errno 36] File name too long:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM