UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 'replace'속성을 읽을 수 없습니다.

user15187112

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of undefined내 파일의 36 행에 오류가 발생 했습니다 index.js(아래 스크립트 참조). Python 하위 프로세스에서 호출하고 있습니다.

참고 : 하위 프로세스를 통해 index.js를 호출해야합니다 .

이상한 이유로 프로그램은 20 %의 시간 동안 작동하지만이 오류가 계속 발생합니다. 이 오류를 어떻게 수정합니까?

main.py

import os
import subprocess

filePath = "/file/path/index.js"

command = subprocess.Popen(["node", filePath, "https://video.com/link"])
stdout, stderr = command.communicate()
command.wait()

오류

(node:64821) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'replace' of undefined
    at /full/path/index.js:36:23
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:64821) 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:64821) [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.

index.js

const urlRegex = require("url-regex");
const fetch = require("node-fetch");
const fs = require("fs");
const https = require("https");

if (process.argv.length <= 2) {
  console.log('Missing URL.');
  console.log('Usage: node index.js <url>');
  process.exit(0);
}

let url = process.argv[2];

if (url.endsWith('/')) url = url.substring(0, url.length - 1);

const urlParts = url.split("/");
let id = urlParts[urlParts.length - 1];

if (id.includes("?")) id = id.split("?")[0];

console.log(`URL > ${url}`);
console.log(`ID > ${id}`);

fetch(url)
  .then(res => {
    return res.text();
  })
  .then(body => {
    const urls = body.match(urlRegex());
    const baseUrl = urls.find(url => url.includes("playlist.m3u8"))

    let liveUrl = baseUrl;
    
    liveUrl = liveUrl.replace("pull-hls", "pull-flv");
    liveUrl = liveUrl.split("/").slice(0, 5).join("/")
    liveUrl += ".flv"

    console.log(`Found live playlist (m3u8) URL: ${baseUrl}`);
    console.log(`Found live flv URL: ${liveUrl}`);

    console.log(`Writing live to output.flv. Press Ctrl C to STOP.`)
    
    const file = fs.createWriteStream('output_path/output.flv')
    https.get(liveUrl, function (response) {
      response.pipe(file);
    });

    fs.writeFile('output_path/completion_check.txt', 'Hello World!', function (err) {
      if (err) return console.log(err);
      console.log('completion_check.txt has been created');
    });

  });

아라 쉬 모타 메디

그 이유는 32 행에서 .find함수가 반환 undefined될 수 .replace있고 undefined에 대해 어떤 메서드 ( 이 경우)도 호출 할 수 없기 때문입니다 .

const baseUrl = urls.find(url => url.includes("playlist.m3u8"))

계속하기 전에이 줄 뒤에 확인을 추가하십시오. 예를 들면 :

if (baseUrl === undefined) {
   console.log("Did not find any matching URLs")
   return;
}

.find작동 방식 에 대한 추가 정보 : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 'send'속성을 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'password'를 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'id'를 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : Sequelize ORM을 사용하여 정의되지 않은 '생성'속성을 읽을 수 없습니다.

분류에서Dev

Socket.io-UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 '방출'을 읽을 수 없습니다.

분류에서Dev

UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 'public_id'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : VueJS 컨텍스트에서 정의되지 않은 'replace'속성을 읽을 수 없습니다.

분류에서Dev

잡히지 않은 TypeError : null jqgrid의 'replace'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '성공'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '고정'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '페이지'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '이미지'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '이미지'속성을 읽을 수 없습니다.

분류에서Dev

Angular : 정의되지 않은 TypeError의 'routeConfig'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 CryptoJS의 '0'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 API의 'ft'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 ReactJS의 'push'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 Reactjs의 'map'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 'name'속성을 읽을 수 없습니다 .TypeError : 정의되지 않은 'name'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 '사용자'속성을 읽을 수 없습니다.

분류에서Dev

React Jest : TypeError : 정의되지 않은 'map'속성을 읽을 수 없습니다.

분류에서Dev

React TypeError : 정의되지 않은 'getDates'속성을 읽을 수 없습니다.

분류에서Dev

MERN-TypeError : 정의되지 않은 'id'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 'formModel'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 속성 'hasOne'을 읽을 수 없습니다.

분류에서Dev

ReactJs-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

분류에서Dev

React Native TypeError : 정의되지 않은 'timeSlots'속성을 읽을 수 없습니다.

분류에서Dev

TypeError : 정의되지 않은 'classList'속성을 읽을 수 없습니다.

분류에서Dev

HtmlWebpackInlineSourcePlugin TypeError : 정의되지 않은 'getHooks'속성을 읽을 수 없습니다.

Related 관련 기사

  1. 1

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 'send'속성을 읽을 수 없습니다.

  2. 2

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'password'를 읽을 수 없습니다.

  3. 3

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 'id'를 읽을 수 없습니다.

  4. 4

    UnhandledPromiseRejectionWarning : TypeError : Sequelize ORM을 사용하여 정의되지 않은 '생성'속성을 읽을 수 없습니다.

  5. 5

    Socket.io-UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 속성 '방출'을 읽을 수 없습니다.

  6. 6

    UnhandledPromiseRejectionWarning : TypeError : 정의되지 않은 'public_id'속성을 읽을 수 없습니다.

  7. 7

    TypeError : VueJS 컨텍스트에서 정의되지 않은 'replace'속성을 읽을 수 없습니다.

  8. 8

    잡히지 않은 TypeError : null jqgrid의 'replace'속성을 읽을 수 없습니다.

  9. 9

    TypeError : 정의되지 않은 '성공'속성을 읽을 수 없습니다.

  10. 10

    TypeError : 정의되지 않은 '고정'속성을 읽을 수 없습니다.

  11. 11

    TypeError : 정의되지 않은 '페이지'속성을 읽을 수 없습니다.

  12. 12

    TypeError : 정의되지 않은 '이미지'속성을 읽을 수 없습니다.

  13. 13

    TypeError : 정의되지 않은 '이미지'속성을 읽을 수 없습니다.

  14. 14

    Angular : 정의되지 않은 TypeError의 'routeConfig'속성을 읽을 수 없습니다.

  15. 15

    TypeError : 정의되지 않은 CryptoJS의 '0'속성을 읽을 수 없습니다.

  16. 16

    TypeError : 정의되지 않은 API의 'ft'속성을 읽을 수 없습니다.

  17. 17

    TypeError : 정의되지 않은 ReactJS의 'push'속성을 읽을 수 없습니다.

  18. 18

    TypeError : 정의되지 않은 Reactjs의 'map'속성을 읽을 수 없습니다.

  19. 19

    TypeError : 정의되지 않은 'name'속성을 읽을 수 없습니다 .TypeError : 정의되지 않은 'name'속성을 읽을 수 없습니다.

  20. 20

    TypeError : 정의되지 않은 '사용자'속성을 읽을 수 없습니다.

  21. 21

    React Jest : TypeError : 정의되지 않은 'map'속성을 읽을 수 없습니다.

  22. 22

    React TypeError : 정의되지 않은 'getDates'속성을 읽을 수 없습니다.

  23. 23

    MERN-TypeError : 정의되지 않은 'id'속성을 읽을 수 없습니다.

  24. 24

    TypeError : 정의되지 않은 'formModel'속성을 읽을 수 없습니다.

  25. 25

    TypeError : 정의되지 않은 속성 'hasOne'을 읽을 수 없습니다.

  26. 26

    ReactJs-TypeError : 정의되지 않은 '맵'속성을 읽을 수 없습니다.

  27. 27

    React Native TypeError : 정의되지 않은 'timeSlots'속성을 읽을 수 없습니다.

  28. 28

    TypeError : 정의되지 않은 'classList'속성을 읽을 수 없습니다.

  29. 29

    HtmlWebpackInlineSourcePlugin TypeError : 정의되지 않은 'getHooks'속성을 읽을 수 없습니다.

뜨겁다태그

보관