Skip to content

Uncaught Error Error: socket hang up #88

@cpp-memory-leaks

Description

@cpp-memory-leaks

Hey guys, why does this error occur? Is it because of my network problem?

H:\nvm\v22.13.0\node.exe .\index.js
iCloud instance created
index.js:15
(node:15300) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
index.js:5
error: {error: 'Two-factor-authentication is required.', code: 15}
index.js:26
need two-step verification, please check the verification code on the device
index.js:30
auth code input
index.js:33
current progress: {parentAction: 'login', action: 'authToken', progress: 0.3333333333333333}
index.js:42
Uncaught Error Error: socket hang up
    at socketCloseListener (_http_client:491:27)
    at emit (events:536:35)
    at <anonymous> (net:351:12)
    at done (_tls_wrap:650:7)
    at callbackTrampoline (internal/async_hooks:130:17)
_http_client:491
Process exited with code 1

const iCloud = require('apple-icloud');
const fs = require('fs');
const path = require('path');
const readline = require('readline');

// iCloud login config
const config = {
  username: "", 
  password: ""
};


// create iCloud instance
const myCloud = new iCloud(); // no session parameter
console.log('iCloud instance created');
// Request SMS security code
myCloud.sendSecurityCode("sms");

myCloud.on('ready', () => {
  console.log('iCloud has connected!');
  
  testConnection();
});

myCloud.on('err', async (error) => {
  console.error('error:', error);

  // handle two-step verification
  if (error.code === 15) {
    console.log('need two-step verification, please check the verification code on the device');
    const code = 55555; 
    myCloud.securityCode = code;
    console.log('auth code input');
  }
});

myCloud.on("ready", function() {
  testConnection(); 
});
// listen progress
myCloud.on('progress', (progress) => {
  console.log('current progress:', progress);
});

myCloud.login(config.username, config.password, async (err) => {
  if (err) {
    console.error('login error:', err);
    await waitForUserInput();
    return;
  }
  console.log('login success');
});

// test connection
async function testConnection() {
  try {
    // try to get contact list
    const contacts = await myCloud.Contacts.list();
    console.log('contract:', contacts.length, 'contracts');
  } catch (err) {
    console.error('test connection error:', err);
  } finally {
    // after test connection, keep the console open
    await waitForUserInput();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions