Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of null (reading '0') #302

Open
mohamedsabith opened this issue Jan 7, 2023 · 15 comments
Open

Cannot read properties of null (reading '0') #302

mohamedsabith opened this issue Jan 7, 2023 · 15 comments

Comments

@mohamedsabith
Copy link

const matches = res.toJSON().body.match(pattern)
value = matches[0].substring(13)
TypeError: Cannot read properties of null (reading '0')
node_modules\instagram-web-api\lib\index.js:57:22

@Strooss
Copy link

Strooss commented Jan 14, 2023

having the same issue here..

@ColdFire87
Copy link

I think the issue is with this code new RegExp(/(csrf_token":")\w+/). It expects the quotes to not be escaped.

Doing a console.log(res.toJSON().body) ... I can see 2 matches for csrf_token ... the first one contains the actual value, but has the quotes escaped -> csrf_token\":\"...\" ... the second one is not escaped, but the value is empty -> csrf_token":"".

The way I got it to work was to replace escaped quotes with non-escaped ones, before matching the regex:

await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.replace(/\\"/g, '"').match(pattern)
      value = matches[0].substring(13)
    })

@Strooss
Copy link

Strooss commented Jan 15, 2023

I think the issue is with this code new RegExp(/(csrf_token":")\w+/). It expects the quotes to not be escaped.

Doing a console.log(res.toJSON().body) ... I can see 2 matches for csrf_token ... the first one contains the actual value, but has the quotes escaped -> csrf_token\":\"...\" ... the second one is not escaped, but the value is empty -> csrf_token":"".

The way I got it to work was to replace escaped quotes with non-escaped ones, before matching the regex:

await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.replace(/\\"/g, '"').match(pattern)
      value = matches[0].substring(13)
    })

i think the package is completely broken..

@dimaspriyanto
Copy link

For my case, Instagram identify unusual login, when i follow the checkpoint URL, they required me to change my password before continue..

StatusCodeError: 400 - {"message":"checkpoint_required","checkpoint_url":"/challenge/action/AXEKy63B9j8ILsr8huijpQn9PEYOzBiY-5vpbN6PDFgowATNdyZrUX1VXivUQaLV-JTF/Afz24OgDEt9wmXbBpuUFsCytJ_mtvkP7OT3aYhJEtJZtsy0dtVT1_qlvE426vXD6vBgLMIO8u-OUVw/ffc_UEvY9OEISw45TL7Pr9Uu6ASkxGOMKWYGuv7xl3Jjodk40sV7IzWyJvaXH63VVOo1/","lock":false,"flow_render_type":0,"status":"fail"}

@AliAryanTech
Copy link

TypeError: Cannot read properties of null (reading '0')

++

@technical-shoubhik
Copy link

(node:2668) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of null
at D:\Codes\NodeJS\ins\node_modules\instagram-web-api\lib\index.js:57:22
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Instagram.login (D:\Codes\NodeJS\ins\node_modules\instagram-web-api\lib\index.js:54:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:2668) 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: 1)
(node:2668) [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.

@quaint-racoon
Copy link

Dude 2 months still not solved

@erhancan256
Copy link

Dude 2 months still not solved

i have same problem pls help

@quaint-racoon
Copy link

I found a solution but theres another porblem

Edit the package and replace the errored code with this

let value = this.request('/', { resolveWithFullResponse: true }).then(res => {
const pattern = new RegExp(/(csrf_token\":\")[\w]+/)
const matches = res.body.match(pattern)
value = matches[0].substring(15)
})

But another error apears

@dmzoneill
Copy link

just tried to use the moduile and hit this also

Apr 04 19:17:51 dave-pc node[1278826]:       value = matches[0].substring(13)
Apr 04 19:17:51 dave-pc node[1278826]:                      ^
Apr 04 19:17:51 dave-pc node[1278826]: TypeError: Cannot read properties of null (reading '0')
Apr 04 19:17:51 dave-pc node[1278826]:     at /home/dave/src/whatsbot/node_modules/instagram-web-api/lib/index.js:57:22
Apr 04 19:17:51 dave-pc node[1278826]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Apr 04 19:17:51 dave-pc node[1278826]:     at async Instagram.login (/home/dave/src/whatsbot/node_modules/instagram-web-api/lib/index.js:54:5)

disappointing

@SGauts
Copy link

SGauts commented Apr 20, 2023

Facing the same issue.
value = matches[0].substring(13) ^ TypeError: Cannot read properties of null (reading '0')
Any fix ?

@alexandre-hallaine
Copy link

alexandre-hallaine commented Apr 29, 2023

i made a fix, just replace this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.match(pattern)
      value = matches[0].substring(13)
    })

with this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token\\":\\")\w+/)
      const matches = res.toJSON().body.match(pattern)
      if (!matches || matches.length === 0)
        throw new Error('Missing CSRFToken')
      value = matches[0].substring(15)
    })

in the file lib/index.js line 53

@quaint-racoon
Copy link

i made a fix, just replace this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token":")\w+/)
      const matches = res.toJSON().body.match(pattern)
      value = matches[0].substring(13)
    })

with this

    let value
    await this.request('/', { resolveWithFullResponse: true }).then(res => {
      const pattern = new RegExp(/(csrf_token\\":\\")\w+/)
      const matches = res.toJSON().body.match(pattern)
      if (!matches || matches.length === 0)
        throw new Error('Missing CSRFToken')
      value = matches[0].substring(15)
    })

in the file lib/index.js line 53

but this creates a new error if u tried running it a request error

@alexandre-hallaine
Copy link

but this creates a new error if u tried running it a request error

can you give the error you got?

@ismaelcolladocala
Copy link

ismaelcolladocala commented May 28, 2023

but this creates a new error if u tried running it a request error

can you give the error you got?

I think the previous guy is talking about this error:

photo_2023-05-28_21-10-49

Which is happening to me after your fix. I inspected all the output from this function:
343a76dd80e8eb90b9a8aa876810b853
Saving it in a file and looking for "window._sharedData" which is the split condition, and there is no "window._sharedData" on that html string.

Is this some change from instagram? Do we know a fix for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests