javascript - 在 nodejs 中发布 url 编码的 Api 但仍然出现错误
问题描述
嗨,我是 javascript 新手,我尝试从 lala.ai 发布 url 编码的 Api。我按照互联网上的说明进行操作,但仍然出现错误。下面我把代码和结果。
//This is the instruction
POST /api/preview/
Puts a file in the preview queue (the first minute of vocals).
Parameters (form-urlencoded):
id (str): File id obtained from /upload/ method.
filter_type (int, optional): Number of postprocess iterations with MWF.
webpush-callback (json, optional): Client data for sending push notifications.
Returns (json):
{
"status": "success" | "error"
"error": Error description if the status is "error"
}
Examples:
$ curl --url https://www.lalal.ai/api/preview/ --form-string "id=9a3ae258-7693-4046-87c2-ef577eb752bb" --form-string "filter_type=2"
{"status": "success"}
$ curl --url https://www.lalal.ai/api/preview/
{"status": "error", "error": "No file id"}
这是我尝试过的
const qs = require("qs");
axios
.post(
"https://www.lalal.ai/api/preview/",
{
data: qs.stringify({
id: "4d2f9262-e578-4290-97d3-43303fffbf56",
filter_type: "2",
}),
},
{
headers: {
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
},
}
)
.then((result) => {
console.log(result);
});
这是我得到的错误结果
(node:34480) UnhandledPromiseRejectionWarning: Error: Request failed with status code 403
at createError (D:\reactjs\upload_lalal\server\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\reactjs\upload_lalal\server\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (D:\reactjs\upload_lalal\server\node_modules\axios\lib\adapters\http.js:244:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:34480) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:34480) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
有人可以向我解释为什么这是错误以及如何解决吗?谢谢。
解决方案
您的错误是... HTTP 403,这意味着
The HTTP 403 is a HTTP status code meaning access to the requested resource is forbidden
您是否需要访问令牌才能使用 API?
推荐阅读
- python - 如何避免基于正则表达式的字符串?
- docker - `docker-compose up`:sqlalchemy.exc.ProgrammingError:(psycopg2.errors.UndefinedTable)关系“连接”不存在
- angular - 如何使用 Apollo Angular 测试查询、变异、订阅服务?
- oauth-2.0 - OAuth2 调用成功后应该做什么?
- c++ - C++ 宏表达式中的井号符号
- javascript - React js TypeError:无法读取未定义的属性“状态”
- javascript - 使用 cypress 上传 pdf 文件
- airflow - 显式跳过 DAG 时的 Slack 通知
- java - 我可以在代号 One 的 Dialog.show 中插入图像吗
- azure-devops - 如何从通用工件包中下载最新版本