如何在python3中与urllib或请求一起使用以下内容
curl --unix-socket /var/run/docker.sock http://localhost/images/json如果可能的话谁来帮我?
发布于 2022-07-14 15:00:36
下面是一个例子。
显然,它的主要优点是它不需要任何依赖关系。
它将一个HTTP request发送到Docker打开的UNIX,以便通过JSON检索容器列表。
async def get_containers():
reader, writer = await asyncio.open_unix_connection("/var/run/docker.sock")
query = (
f"GET /containers/json HTTP/1.0\r\n"
f"\r\n"
)
writer.write(query.encode('utf-8'))
await writer.drain()
writer.write_eof()
headers = True
while headers:
line = await reader.readline()
if line == b"\r\n":
headers = False
elif not line:
break
containers = []
if not headers:
data = await reader.readline()
containers = json.loads(data.decode("utf-8"))
writer.close()
await writer.wait_closed()
return containers
c = asyncio.run(get_containers())https://stackoverflow.com/questions/68716830
复制相似问题