Deno 权限问题 - Uncaught PermissionDenied: network access

Deno permissions issue - Uncaught PermissionDenied: network access

我正在尝试 Deno,虽然 运行 是一个例子,但我 运行 出错了:

$ deno run https://deno.land/std/examples/curl.ts https://example.com
Download https://deno.land/std/examples/curl.ts
Warning Implicitly using master branch https://deno.land/std/examples/curl.ts
Compile https://deno.land/std/examples/curl.ts
error: Uncaught PermissionDenied: network access to "https://example.com/", run again with the --allow-net flag
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
    at async fetch ($deno$/web/fetch.ts:591:27)
    at async https://deno.land/std/examples/curl.ts:3:13

我试过

$ deno run https://deno.land/std/examples/curl.ts https://example.com --allow-net

但仍然出现同样的错误。我做错了什么?

--allow-net标志必须deno run之后和文件名之前,而不是附加在末尾。

deno run --allow-net https://deno.land/std/examples/curl.ts https://example.com

详细了解 Deno permissions here

--allow-env                    
    Allow environment access

--allow-hrtime                 
    Allow high resolution time measurement

--allow-net=<allow-net>        
    Allow network access

--allow-plugin                 
    Allow loading plugins

--allow-read=<allow-read>      
    Allow file system read access

--allow-run                    
    Allow running subprocesses

--allow-write=<allow-write>    
    Allow file system write access

例子

    deno run --allow-net app.ts //give a network permission

    deno run --allow-all app.ts //give an all permission

Deno is a runtime which is secure by default. This means you need to explicitly give programs the permission to do certain 'privileged' actions, such as access the network.

利用 --allow-net=<domain> 权限标志:在您的情况下 deno run --allow-net=example.com https://deno.land/std/examples/curl.ts https://example.com

如果您不提供域名,它将允许所有可能再次成为安全威胁的域。看这里 Permission.