admin管理员组文章数量:1310099
Below is my python code where I am trying to pass kubeseal_cmd and run_options to subprocess.run method, but it's giving me error
No overload variant of subprocess.run matches argument types list[str], dict[str,object].
What am I missing? I am using python 3.12
kubeseal_path = "/var/tmp/workspace/file.txt"
secret = yaml.safe_load(secret_File.read().encode("utf-8"))
cert_file = = "/var/tmp/workspace/file123.txt"
kubeseal_cmd = [
kubeseal_path,
"--cert",
cert_file,
"--format=yaml",
"</dev/stdin>"
]
run_options = {
"env": {},
"stdout": subprocess.PIPE,
"check": True,
"input": yaml.dump(secret).encode(),
}
sealed_secret = yaml.safe_load(subprocess.run(kubeseal_cmd, **run_options).stdout.decode().strip())
Below is my python code where I am trying to pass kubeseal_cmd and run_options to subprocess.run method, but it's giving me error
No overload variant of subprocess.run matches argument types list[str], dict[str,object].
What am I missing? I am using python 3.12
kubeseal_path = "/var/tmp/workspace/file.txt"
secret = yaml.safe_load(secret_File.read().encode("utf-8"))
cert_file = = "/var/tmp/workspace/file123.txt"
kubeseal_cmd = [
kubeseal_path,
"--cert",
cert_file,
"--format=yaml",
"</dev/stdin>"
]
run_options = {
"env": {},
"stdout": subprocess.PIPE,
"check": True,
"input": yaml.dump(secret).encode(),
}
sealed_secret = yaml.safe_load(subprocess.run(kubeseal_cmd, **run_options).stdout.decode().strip())
Share
Improve this question
edited Jan 15 at 19:27
InSync
10.4k4 gold badges15 silver badges51 bronze badges
asked Jan 13 at 19:51
BokamboBokambo
4,48028 gold badges87 silver badges146 bronze badges
11
|
Show 6 more comments
1 Answer
Reset to default 1The Easy Answer
"Hey, doctor, it hurts when I do this!"
"Don't do that"
Nothing your code is doing requires the run_options
dict. Take it out and the problem is mooted:
sealed_secret = yaml.safe_load(
subprocess.run(
kubeseal_cmd,
env={},
stdout=subprocess.PIPE,
check=True,
input=yaml.dump(secret).encode(),
).stdout.decode().strip()
)
The Other Approach
If you really want to be able to represent keyword arguments in a dict, you can do that by building a TypedDict
setting out the type of each item.
Note that this requires a quite current Python release -- the below code is tested on Python 3.12.
from typing import Any, Literal, TypedDict, NotRequired, IO
class RunOptions(TypedDict):
env: NotRequired[dict[str, str]]
check: NotRequired[bool]
input: NotRequired[None|str|bytes]
stdout: NotRequired[int | IO[Any]]
run_options = RunOptions({
"env": {},
"stdout": subprocess.PIPE,
"check": True,
"input": yaml.dump(secret).encode(),
})
sealed_secret = yaml.safe_load(
subprocess.run(kubeseal_cmd, **run_options).stdout.decode().strip()
)
本文标签:
版权声明:本文标题:python - No overload variant of subprocess.run matches argument types list[str], dict[str,object] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737422100a1988855.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
**
). A real error would have an exception and stack trace. Anyhow -- why are you using arun_options
dict at all? If you inline the keyword arguments (ditchrun_options
entirely and instead passcheck=True
&c), I'd expect that to moot the immediate issue. – Charles Duffy Commented Jan 13 at 21:32TypedDict
definition that matches the subprocess.run kwargs to make the typechecker work right under these circumstances, but I don't see any reason it would be worth the bother. – Charles Duffy Commented Jan 13 at 22:35mypy
,pylint
, etc. – Barmar Commented Jan 14 at 1:36