我正在学习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.中检查非常相似问题的解决方案建议
这是简单的问题描述:
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
这是一个解决方案:
这是另一个solution示例。
关于node.js - Deno:在Docker容器上写入CSV文件(权限被拒绝(操作系统错误13)),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62316052/