gpt4 book ai didi

node.js - Deno:在Docker容器上写入CSV文件(权限被拒绝(操作系统错误13))

转载 作者:行者123 更新时间:2023-12-02 19:48:16 25 4
gpt4 key购买 nike

我正在学习Deno的问题,并且在使用Deno writeCSV()实用程序写入CSV文件时遇到权限问题。我已经搭建了该项目以在顶级Docker上运行

Dockerfile
CMD ["run", "--allow-read", "--allow-run", "--allow-write", "--allow-net", "main.ts"]
维护


import { serve, readCSV, writeCSV } from "./deps.ts";

const URL = "https://www.getcats.com/api"
const DEFAULT_PRODUCT_ID = "xxxxxxxxxxxx";
const DEFAULT_DESCRIPTION = "Description";
const options = {
method: "POST",
url: URL,
body: {},
headers: {
"x-api-key": "xxxxxxxxxxxxx"
},
json: true // Automatically stringifies the body to JSON
};

// CSV File Properties
const f = await Deno.open("./inbound/example.csv");
const outputFile = await Deno.open("./outbound/outbound.csv", { write: true, create: true, read: true, truncate: true });

for await (const row of readCSV(f)) {
for await (const cell of row) {
queueMicrotask(async () => {

const response = await fetch(URL, {
method: "POST",
headers: {
'content-type': 'application/json',
"x-api-key": "xxxxxxxxxxxxxxx"
},
body: JSON.stringify({
memberId: cell,
productId: DEFAULT_PRODUCT_ID,
description: DEFAULT_DESCRIPTION
}),
});

response.json()
.then(async (res)=> {
const data = res.data;
const memberId = data.memberId;
const hashId = data.id;
const rows = [memberId, hashId]
console.log(`CAT ID: ${memberId} - HASH ID: ${hashId}`);

await writeCSV(outputFile, rows);
outputFile.close();

})

})

}
}
f.close();


我认为运行容器时通过 ---allow-write发送将解决此烫发问题。还有其他人在通过Docker向Deno中的目录写入时遇到问题吗?

最佳答案

您能否从博客here.中检查非常相似问题的解决方案建议

这是简单的问题描述:

One thing I ran into was that initially, the Dockerfile specified a user with limited permissions. This throws a very cryptic exception:


error: Uncaught PermissionDenied: Permission denied (os error 13)
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
at Object.listen ($deno$/ops/net.ts:51:10)
at listen ($deno$/net.ts:152:22)
at serve (https://deno.land/std@0.50.0/http/server.ts:261:20)
at file:///app/main.ts:4:11

这是一个解决方案:

As it turns out, this was because we want to serve the application on port 80. Non-privileged user (not root) can't open a listening socket on ports below 1024. Make sure that user running the process (which can be specified by using USER in your Dockerfile) has enough permission. In our case, just omitting the USER works just fine.



这是另一个 solution示例。

关于node.js - Deno:在Docker容器上写入CSV文件(权限被拒绝(操作系统错误13)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62316052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com