airgram / airgram-js-example

Basic usage Airgram with JavaScript
GNU General Public License v3.0
13 stars 7 forks source link

NETWORK_BAD_RESPONSE error #1

Closed James2516 closed 5 years ago

James2516 commented 5 years ago

Environment: Node: v8.15.0 MacOS 10.14

I tried to run the example (after setting process.env.APP_ID and process.env.APP_HASH) but received the following error. Is there something else I need to configure?

{ RpcError: CODE#406 NETWORK_BAD_RESPONSE
    at Object.rejectPromise [as reject] (/Users/a/Desktop/Github/airgram-js-example/node_modules/airgram/base/MtpAuthorizer.js:286:66)
    at /Users/a/Desktop/Github/airgram-js-example/node_modules/airgram/base/MtpAuthorizer.js:152:33
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  name: 'RpcError',
  type: 'NETWORK_BAD_RESPONSE',
  code: 406,
  message: 'CODE#406 NETWORK_BAD_RESPONSE',
  original: 
   { Error: Request failed with status code 404
    at createError (/Users/a/Desktop/Github/airgram-js-example/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/a/Desktop/Github/airgram-js-example/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/Users/a/Desktop/Github/airgram-js-example/node_modules/axios/lib/adapters/http.js:201:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
     config: 
      { adapter: [Function: httpAdapter],
        transformRequest: [Object],
        transformResponse: [Function: transformResponse],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        validateStatus: [Function: validateStatus],
        headers: [Object],
        method: 'post',
        data: ArrayBuffer { byteLength: 344 },
        responseType: 'arraybuffer',
        url: 'http://149.154.167.51:443/apiw1' },
     request: 
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'POST /apiw1 HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 344\r\nHost: 149.154.167.51:443\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/apiw1',
        _ended: true,
        res: [Object],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Object],
        [Symbol(outHeadersKey)]: [Object] },
     response: 
      { status: 404,
        statusText: 'Not Found',
        headers: [Object],
        config: [Object],
        request: [Object],
        data: ArrayBuffer { byteLength: 169 } } },
  url: 'http://149.154.167.51:443/apiw1',
  toString: [Function] }
esindger commented 5 years ago

Sometimes I also see a similar error during the creation of authorization keys. The reason has not yet been found out. After successfully creating the keys the error disappears.

Please try to execute the npm run dev command again. Is error occurring?

James2516 commented 5 years ago

@esindger seems to be getting a different error now. Where does /data/airgram/LOCK file come from?

  airgram info    15:19:25.991 [Client] callApi() "messages.getDialogs" {"limit":30,"offset_date":0,"offset_id":0,"offset_peer":{"_":"inputPeerEmpty"}} +0ms
  airgram error   15:19:25.996 [Auth] middleware() "messages.getDialogs" you are not authorized +3ms
  airgram error   15:19:25.997 [Client] [messages.getDialogs]: (intermediate value)(intermediate value)(intermediate value).finally is not a function {} +1ms
  airgram verbose 15:19:25.998 [Auth] ask() 'phoneNumber' +1ms
Please enter your phone number:

TypeError: (intermediate value)(intermediate value)(intermediate value).finally is not a function
    at Auth.login (/node_modules/airgram/base/Auth.js:203:95)
    at Auth.<anonymous> (/node_modules/airgram/base/Auth.js:238:56)
    at step (/node_modules/airgram/base/Auth.js:68:23)
    at Object.next (/node_modules/airgram/base/Auth.js:49:53)
    at fulfilled (/node_modules/airgram/base/Auth.js:40:58)
    at <anonymous>
  airgram verbose 15:19:26.003 [MtpAuthorizer] sendReqPQ() Send req_pq e470c72077dda56017e4498f7ba9574a +5ms
  airgram verbose 15:19:26.005 [MtpAuthorizer] sendNetworkRequest() "http://149.154.167.51:443/apiw1" +2ms
  airgram verbose 15:19:26.649 [MtpAuthorizer] mtpSendReqPQ() Got ResPQ bf4d89262abe86c682774ebade5cdea8 273949f87f530187 14101943622620965665 +644ms
  airgram verbose 15:19:26.650 [MtpAuthorizer] mtpSendReqPQ() 'PQ factorization start 39,57,73,248,127,83,1,135 +1ms
  airgram verbose 15:19:27.065 [MtpAuthorizer] mtpSendReqPQ() 'PQ factorization done 24944 +415ms
  airgram verbose 15:19:27.070 [MtpAuthorizer] mtpSendReqDhParams() dc "2" +5ms
  airgram verbose 15:19:27.071 [MtpAuthorizer] sendNetworkRequest() "http://149.154.167.51:443/apiw1" +1ms
  airgram verbose 15:19:27.716 [MtpAuthorizer] mtpDecryptServerDhDataAnswer() Done decrypting answer +645ms
  airgram verbose 15:19:27.716 [MtpAuthorizer] mtpVerifyDhParams() Verifying DH params +0ms
  airgram verbose 15:19:27.716 [MtpAuthorizer] mtpVerifyDhParams() dhPrime cmp OK +0ms
  airgram verbose 15:19:27.717 [MtpAuthorizer] mtpVerifyDhParams() 1 < gA < dhPrime-1 OK +1ms
  airgram verbose 15:19:27.717 [MtpAuthorizer] mtpVerifyDhParams() 2^{2048-64} < gA < dhPrime-2^{2048-64} OK +1ms
  airgram verbose 15:19:27.902 [MtpAuthorizer] mtpSendSetClientDhParams() Send set_client_DH_params +184ms
  airgram verbose 15:19:27.903 [MtpAuthorizer] sendNetworkRequest() "http://149.154.167.51:443/apiw1" +1ms
  airgram verbose 15:19:28.925 [MtpAuthorizer] mtpSendSetClientDhParams() Got Set_client_DH_params_answer dh_gen_ok +1s
  airgram error   15:19:28.927 [Client] [getMtpClient]: IO error: /data/airgram/LOCK: No such file or directory {} +2ms
  airgram error   15:19:28.927 [Client] [startPolling]: IO error: /data/airgram/LOCK: No such file or directory {} +0ms
OpenError: IO error: /data/airgram/LOCK: No such file or directory
    at /node_modules/levelup/lib/levelup.js:91:23
    at /node_modules/deferred-leveldown/node_modules/abstract-leveldown/abstract-leveldown.js:41:14
    at /node_modules/deferred-leveldown/deferred-leveldown.js:20:21
    at /node_modules/abstract-leveldown/abstract-leveldown.js:41:14
airgram commented 5 years ago

This is PouchDB store files. Please create the /data directory manually. It will be fixed in the next commit.

James2516 commented 5 years ago

This is the error I'm getting now. Am I correct to assume the phone number should include country code but not '+' or spaces?

  airgram info    15:42:23.872 [MtpClient][1] startPolling() dc "2" +0ms
  airgram info    15:42:23.875 [MtpClient][1] checkConnection() +2ms
Long polling error
TypeError: this.getState(...).then(...).finally is not a function
    at Updates.getDifference (airgram-js-example/node_modules/airgram/base/Updates.js:140:21)
    at airgram-js-example/node_modules/airgram/base/Updates.js:208:75
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  airgram info    15:42:23.893 [Client] callApi() "updates.getState" undefined +18ms
(node:17683) UnhandledPromiseRejectionWarning: TypeError: this.client.updates.getState(...).then(...).finally is not a function
    at Updates.<anonymous> (airgram-js-example/node_modules/airgram/base/Updates.js:240:41)
    at step (airgram-js-example/node_modules/airgram/base/Updates.js:57:23)
    at Object.next (airgram-js-example/node_modules/airgram/base/Updates.js:38:53)
    at fulfilled (airgram-js-example/node_modules/airgram/base/Updates.js:29:58)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:17683) 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: 2)
(node:17683) [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.
  airgram error   15:42:23.897 [Auth] middleware() "updates.getState" you are not authorized +4ms
  airgram error   15:42:23.898 [Client] [updates.getState]: (intermediate value)(intermediate value)(intermediate value).finally is not a function {} +1ms
  airgram verbose 15:42:23.899 [Auth] ask() 'samePhoneNumber' +1ms
  airgram verbose 15:42:23.900 [Auth] ask() next state '{
  airgram   "phoneNumber": "xxxxxxxxxx",
  airgram   "_id": "airgram:auth",
  airgram   "_rev": "1-6d7386087ac191fe08d46d6ef46dcff3",
  airgram   "samePhoneNumber": false
  airgram }' +1ms
(node:17683) UnhandledPromiseRejectionWarning: TypeError: (intermediate value)(intermediate value)(intermediate value).finally is not a function
    at Auth.login (airgram-js-example/node_modules/airgram/base/Auth.js:203:95)
    at Auth.<anonymous> (airgram-js-example/node_modules/airgram/base/Auth.js:238:56)
    at step (airgram-js-example/node_modules/airgram/base/Auth.js:68:23)
    at Object.next (airgram-js-example/node_modules/airgram/base/Auth.js:49:53)
    at fulfilled (airgram-js-example/node_modules/airgram/base/Auth.js:40:58)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:17683) 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: 3)
  airgram verbose 15:42:23.908 [Auth] ask() 'phoneNumber' +8ms
  airgram verbose 15:42:23.908 [Auth] ask() next state '{
  airgram   "phoneNumber": "xxxxxxxxxx",
  airgram   "_id": "airgram:auth",
  airgram   "_rev": "1-6d7386087ac191fe08d46d6ef46dcff3",
  airgram   "samePhoneNumber": false
  airgram }' +0ms
  airgram info    15:42:23.911 [Client] callApi() "auth.sendCode" {"api_hash":"48df57b6db7b1a2d1f13b14f77184f84","api_id":647385,"current_number":false,"flags":0,"phone_number":"xxxxxxxxxx"} +3ms
  airgram info    15:42:23.912 [MtpRequest][1] request() dc "2" "auth.sendCode" {
  airgram  "api_hash": "48df57b6db7b1a2d1f13b14f77184f84",
  airgram  "api_id": 647385,
  airgram  "current_number": false,
  airgram  "flags": 0,
  airgram  "phone_number": "xxxxxxxxxx"
  airgram } {"isFileTransfer":false,"mtp":{},"timeout":30} +1ms
  airgram verbose 15:42:23.914 [MtpClient][1] wrapApiCall() auth.sendCode {
  airgram   "api_hash": "48df57b6db7b1a2d1f13b14f77184f84",
  airgram   "api_id": 647385,
  airgram   "current_number": false,
  airgram   "flags": 0,
  airgram   "phone_number": "xxxxxxxxxx"
  airgram } 6648481141286390668 1 {} +2ms
  airgram verbose 15:42:23.914 [MtpClient][1] pushMessage() {} +0ms
  airgram verbose 15:42:23.915 [MtpClient][1] sendScheduledRequest() [] +1ms
  airgram verbose 15:42:23.916 [MtpClient][1] sendScheduledRequest() Container[
  airgram   "6648481141286390668",
  airgram   "6648481141290468132"
  airgram ] 6648481141290529004 4 +1ms
  airgram error   15:42:23.919 [MtpClient][1] sendScheduledRequest() "_this.client.network.sendRequest(...).then(...).catch(...).finally is not a function" +3ms
  airgram info    15:42:23.919 [MtpClient][1] toggleOffline() "true"  +0ms
  airgram info    15:42:25.923 [MtpClient][1] checkConnection() +2s
  airgram info    15:42:28.929 [MtpClient][1] checkConnection() +3s
  airgram info    15:42:32.935 [MtpClient][1] checkConnection() +4s
  airgram info    15:42:38.942 [MtpClient][1] checkConnection() +6s
airgram commented 5 years ago

Support of Promise.prototype.finally is coming in Node 10. Can you upgrade Node?

James2516 commented 5 years ago

Tried with Node v10.15.0, received the following error during npm i:

/airgram-js-example$ npm i
npm WARN rm not removing /airgram-js-example/node_modules/.bin/prebuild-install as it wasn't installed by /airgram-js-example/node_modules/prebuild-install
npm WARN rm not removing /airgram-js-example/node_modules/.bin/nopt as it wasn't installed by /airgram-js-example/node_modules/nopt

> fsevents@1.2.6 install /airgram-js-example/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[fsevents] Success: "/airgram-js-example/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" is installed via remote

> leveldown@3.0.0 install /airgram-js-example/node_modules/leveldown
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=10.15.0 runtime=node arch=x64 platform=darwin)
  CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/builder.o
In file included from ../deps/leveldb/leveldb-1.20/db/builder.cc:5:
In file included from ../deps/leveldb/leveldb-1.20/db/builder.h:8:
In file included from ../deps/leveldb/leveldb-1.20/include/leveldb/status.h:16:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:203:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:145:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
...

/usr/local/include/stdint.h:2:10: error: #include nested too deeply
#include <stddef.h>
         ^
/usr/local/include/stdint.h:59:11: error: #include nested too deeply
# include <stdint.h>
          ^
/usr/local/include/stdint.h:72:11: error: #include nested too deeply
# include <sys/types.h>
          ^
/usr/local/include/stdint.h:76:10: error: #include nested too deeply
#include <limits.h>
         ^
/usr/local/include/stdint.h:82:11: error: #include nested too deeply
# include <inttypes.h>
          ^
In file included from ../deps/leveldb/leveldb-1.20/db/builder.cc:5:
In file included from ../deps/leveldb/leveldb-1.20/db/builder.h:8:
In file included from ../deps/leveldb/leveldb-1.20/include/leveldb/status.h:16:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:477:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:203:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:161:8: error: no member named 'uint64_t' in the global namespace
using::uint64_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:163:8: error: no member named 'int_least8_t' in the global namespace
using::int_least8_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:164:8: error: no member named 'int_least16_t' in the global namespace
using::int_least16_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:165:8: error: no member named 'int_least32_t' in the global namespace
using::int_least32_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:166:8: error: no member named 'int_least64_t' in the global namespace
using::int_least64_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:168:8: error: no member named 'uint_least8_t' in the global namespace
using::uint_least8_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:169:8: error: no member named 'uint_least16_t' in the global namespace
using::uint_least16_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:170:8: error: no member named 'uint_least32_t' in the global namespace
using::uint_least32_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:171:8: error: no member named 'uint_least64_t' in the global namespace
using::uint_least64_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:173:8: error: no member named 'int_fast8_t' in the global namespace
using::int_fast8_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:174:8: error: no member named 'int_fast16_t' in the global namespace
using::int_fast16_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:175:8: error: no member named 'int_fast32_t' in the global namespace
using::int_fast32_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:176:8: error: no member named 'int_fast64_t' in the global namespace
using::int_fast64_t;
     ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstdint:178:8: error: no member named 'uint_fast8_t' in the global namespace
using::uint_fast8_t;
     ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/builder.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/.nvm/versions/node/v10.15.0/bin/node" "/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /airgram-js-example/node_modules/leveldown
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@3.0.0 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the leveldown@3.0.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /.npm/_logs/2019-01-20T08_01_14_937Z-debug.log
airgram commented 5 years ago

Did you remove node_modules and package-lock.json before npm i?

James2516 commented 5 years ago

Resolved with node v10, thanks! Installation problem was due to some Brew issues.