代码可以在我的机器上运行,但不能在托管中运行
我已经使用“instagram-private-api”npm 包来随着时间的推移更改我的 instagram 个人资料的简介。该代码可以在我的本地计算机上运行,但不能在我的 ubuntu 托管(azure)上运行。
这是代码:
const { IgApiClient } = require("instagram-private-api")
const ig = new IgApiClient()
const USERNAME = "username"
const PASSWORD = "pass"
ig.state.generateDevice(USERNAME)
const main = async () => {
await ig.simulate.preLoginFlow()
await ig.account.login(USERNAME, PASSWORD)
// log out of Instagram when done
process.nextTick(async () => await ig.simulate.postLoginFlow())
// change the bio
await ig.account.setBiography("testing stuff...")
}
main()
这是出现的错误:
(node:1470) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/accounts/msisdn_header_bootstrap/ - 302 Found;
at Request.handleResponseError (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:126:16)
at Request.send (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:54:28)
(node:1470) 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(). (rejection id: 1)
(node:1470) [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.
请帮助我解决这个问题,TIA!
I have used the "instagram-private-api" npm package to change the bio of my intagram profile over time. the code is working on my local machine but not on my ubuntu hosting(azure).
Here is the code:
const { IgApiClient } = require("instagram-private-api")
const ig = new IgApiClient()
const USERNAME = "username"
const PASSWORD = "pass"
ig.state.generateDevice(USERNAME)
const main = async () => {
await ig.simulate.preLoginFlow()
await ig.account.login(USERNAME, PASSWORD)
// log out of Instagram when done
process.nextTick(async () => await ig.simulate.postLoginFlow())
// change the bio
await ig.account.setBiography("testing stuff...")
}
main()
Here is the error that comes:
(node:1470) UnhandledPromiseRejectionWarning: IgResponseError: POST /api/v1/accounts/msisdn_header_bootstrap/ - 302 Found;
at Request.handleResponseError (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:126:16)
at Request.send (/home/mamba/node_modules/instagram-private-api/dist/core/request.js:54:28)
(node:1470) 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(). (rejection id: 1)
(node:1470) [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.
Please Help me with this problem, TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里给定程序中编写的所有异步函数可能会也可能不会返回值。因此,如果没有收到来自异步函数的任何响应,则预计会出现 .catch(...) 块。
缺少 .catch(..) 是您收到 未处理的承诺拒绝错误 的原因。
您可以使用以下内容:
您必须将其添加到异步函数的末尾。
因此,如果发生故障,.catch(...) 将捕获错误,并且您还可以在发生此类事件时添加其他逻辑。
您可以参考以下文章:
Node.js 中的 Promises (stackabuse.com)
<一href="https://www.geeksforgeeks.org/node-js-process-unhandledpromiserejection-event/#:%7E:text=The%20unhandledRejection%20event%20is% 20emissed%20whenever%20a%20promise,处理程序%20to%20handle%20it%20in%20the%20promise%20chain.?msclkid=792022fea99711eca88d6c7e9f4d5b13" rel="nofollow noreferrer">Node.js 处理 unhandledPromiseRejection 事件 - GeeksforGeeks
javascript - 什么是未处理的承诺拒绝? - Stack Overflow
什么是未处理的 Promise 拒绝? | TOMDUFYTECH.COM
Here all the async function written in the given program may or may not return a value . Thus in an event of not receiving any response from the async function a .catch(...) block is expected .
The lack of the .catch(..) is the reason you are getting the unhandled promise rejection error .
You can use the following :
You have to add this at the end of the async functions .
Thus in an event of event of failure the .catch(...) will catch the error and you can also add additional logic when such events occur .
You can refer the following article :
Promises in Node.js (stackabuse.com)
Node.js Process unhandledPromiseRejection Event - GeeksforGeeks
javascript - What is an unhandled promise rejection? - Stack Overflow
What is an unhandled promise rejection? | TOMDUFFYTECH.COM