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

StatusCodeError: 500 - "Host header is specified and is not an IP address or localhost." #4

Closed
hadrien-toma opened this issue Apr 29, 2018 · 9 comments

Comments

@hadrien-toma
Copy link

hadrien-toma commented Apr 29, 2018

Work done

What I am doing is simply cloning the repository, going into it, editing index.js in order to have the details about the error I have, then running docker-compose up.

Logs got

Starting dockerizedpuppeteer_chrome_1 ... done
Starting dockerizedpuppeteer_app_1 ... done
Attaching to dockerizedpuppeteer_chrome_1, dockerizedpuppeteer_app_1
chrome_1  | [0429/093913.353325:ERROR:gpu_process_transport_factory.cc(1017)] Lost UI shared context.
chrome_1  |
chrome_1  | DevTools listening on ws://0.0.0.0:9222/devtools/browser/6ceb7ace-6012-4c84-9be6-b5dada81dfeb
app_1     |
app_1     | > [email protected] start /app
app_1     | > node src/index.js
app_1     |
app_1     | { StatusCodeError: 500 - "Host header is specified and is not an IP address or localhost."
app_1     |     at new StatusCodeError (/app/node_modules/request-promise-core/lib/errors.js:32:15)
app_1     |     at Request.plumbing.callback (/app/node_modules/request-promise-core/lib/plumbing.js:104:33)
app_1     |     at Request.RP$callback [as _callback] (/app/node_modules/request-promise-core/lib/plumbing.js:46:31)
app_1     |     at Request.self.callback (/app/node_modules/request/request.js:186:22)
app_1     |     at emitTwo (events.js:126:13)
app_1     |     at Request.emit (events.js:214:7)
app_1     |     at Request.<anonymous> (/app/node_modules/request/request.js:1163:10)
app_1     |     at emitOne (events.js:116:13)
app_1     |     at Request.emit (events.js:211:7)
app_1     |     at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1085:12)
app_1     |   name: 'StatusCodeError',
app_1     |   statusCode: 500,
app_1     |   message: '500 - "Host header is specified and is not an IP address or localhost."',
app_1     |   error: 'Host header is specified and is not an IP address or localhost.',
app_1     |   options:
app_1     |    { uri: 'http://chrome:9222/json/version',
app_1     |      json: true,
app_1     |      resolveWithFullResponse: true,
app_1     |      callback: [Function: RP$callback],
app_1     |      transform: undefined,
app_1     |      simple: true,
app_1     |      transform2xxOnly: false },
app_1     |   response:
app_1     |    IncomingMessage {
app_1     |      _readableState:
app_1     |       ReadableState {
app_1     |         objectMode: false,
app_1     |         highWaterMark: 16384,
app_1     |         buffer: [Object],
app_1     |         length: 0,
app_1     |         pipes: null,
app_1     |         pipesCount: 0,
app_1     |         flowing: true,
app_1     |         ended: true,
app_1     |         endEmitted: true,
app_1     |         reading: false,
app_1     |         sync: true,
app_1     |         needReadable: false,
app_1     |         emittedReadable: false,
app_1     |         readableListening: false,
app_1     |         resumeScheduled: false,
app_1     |         destroyed: false,
app_1     |         defaultEncoding: 'utf8',
app_1     |         awaitDrain: 0,
app_1     |         readingMore: false,
app_1     |         decoder: null,
app_1     |         encoding: null },
app_1     |      readable: false,
app_1     |      domain: null,
app_1     |      _events:
app_1     |       { end: [Array],
app_1     |         close: [Array],
app_1     |         data: [Function],
app_1     |         error: [Function] },
app_1     |      _eventsCount: 4,
app_1     |      _maxListeners: undefined,
app_1     |      socket:
app_1     |       Socket {
app_1     |         connecting: false,
app_1     |         _hadError: false,
app_1     |         _handle: null,
app_1     |         _parent: null,
app_1     |         _host: 'chrome',
app_1     |         _readableState: [Object],
app_1     |         readable: false,
app_1     |         domain: null,
app_1     |         _events: [Object],
app_1     |         _eventsCount: 8,
app_1     |         _maxListeners: undefined,
app_1     |         _writableState: [Object],
app_1     |         writable: false,
app_1     |         allowHalfOpen: false,
app_1     |         _bytesDispatched: 94,
app_1     |         _sockname: null,
app_1     |         _pendingData: null,
app_1     |         _pendingEncoding: '',
app_1     |         server: null,
app_1     |         _server: null,
app_1     |         parser: null,
app_1     |         _httpMessage: [Object],
app_1     |         read: [Function],
app_1     |         _consuming: true,
app_1     |         _idleNext: null,
app_1     |         _idlePrev: null,
app_1     |         _idleTimeout: -1,
app_1     |         [Symbol(asyncId)]: 10,
app_1     |         [Symbol(bytesRead)]: 144 },
app_1     |      connection:
app_1     |       Socket {
app_1     |         connecting: false,
app_1     |         _hadError: false,
app_1     |         _handle: null,
app_1     |         _parent: null,
app_1     |         _host: 'chrome',
app_1     |         _readableState: [Object],
app_1     |         readable: false,
app_1     |         domain: null,
app_1     |         _events: [Object],
app_1     |         _eventsCount: 8,
app_1     |         _maxListeners: undefined,
app_1     |         _writableState: [Object],
app_1     |         writable: false,
app_1     |         allowHalfOpen: false,
app_1     |         _bytesDispatched: 94,
app_1     |         _sockname: null,
app_1     |         _pendingData: null,
app_1     |         _pendingEncoding: '',
app_1     |         server: null,
app_1     |         _server: null,
app_1     |         parser: null,
app_1     |         _httpMessage: [Object],
app_1     |         read: [Function],
app_1     |         _consuming: true,
app_1     |         _idleNext: null,
app_1     |         _idlePrev: null,
app_1     |         _idleTimeout: -1,
app_1     |         [Symbol(asyncId)]: 10,
app_1     |         [Symbol(bytesRead)]: 144 },
app_1     |      httpVersionMajor: 1,
app_1     |      httpVersionMinor: 1,
app_1     |      httpVersion: '1.1',
app_1     |      complete: true,
app_1     |      headers: { 'content-length': '63', 'content-type': 'text/html' },
app_1     |      rawHeaders: [ 'Content-Length', '63', 'Content-Type', 'text/html' ],
app_1     |      trailers: {},
app_1     |      rawTrailers: [],
app_1     |      upgrade: false,
app_1     |      url: '',
app_1     |      method: null,
app_1     |      statusCode: 500,
app_1     |      statusMessage: 'Internal Server Error',
app_1     |      client:
app_1     |       Socket {
app_1     |         connecting: false,
app_1     |         _hadError: false,
app_1     |         _handle: null,
app_1     |         _parent: null,
app_1     |         _host: 'chrome',
app_1     |         _readableState: [Object],
app_1     |         readable: false,
app_1     |         domain: null,
app_1     |         _events: [Object],
app_1     |         _eventsCount: 8,
app_1     |         _maxListeners: undefined,
app_1     |         _writableState: [Object],
app_1     |         writable: false,
app_1     |         allowHalfOpen: false,
app_1     |         _bytesDispatched: 94,
app_1     |         _sockname: null,
app_1     |         _pendingData: null,
app_1     |         _pendingEncoding: '',
app_1     |         server: null,
app_1     |         _server: null,
app_1     |         parser: null,
app_1     |         _httpMessage: [Object],
app_1     |         read: [Function],
app_1     |         _consuming: true,
app_1     |         _idleNext: null,
app_1     |         _idlePrev: null,
app_1     |         _idleTimeout: -1,
app_1     |         [Symbol(asyncId)]: 10,
app_1     |         [Symbol(bytesRead)]: 144 },
app_1     |      _consuming: true,
app_1     |      _dumped: false,
app_1     |      req:
app_1     |       ClientRequest {
app_1     |         domain: null,
app_1     |         _events: [Object],
app_1     |         _eventsCount: 5,
app_1     |         _maxListeners: undefined,
app_1     |         output: [],
app_1     |         outputEncodings: [],
app_1     |         outputCallbacks: [],
app_1     |         outputSize: 0,
app_1     |         writable: true,
app_1     |         _last: true,
app_1     |         upgrading: false,
app_1     |         chunkedEncoding: false,
app_1     |         shouldKeepAlive: false,
app_1     |         useChunkedEncodingByDefault: false,
app_1     |         sendDate: false,
app_1     |         _removedConnection: false,
app_1     |         _removedContLen: false,
app_1     |         _removedTE: false,
app_1     |         _contentLength: 0,
app_1     |         _hasBody: true,
app_1     |         _trailer: '',
app_1     |         finished: true,
app_1     |         _headerSent: true,
app_1     |         socket: [Object],
app_1     |         connection: [Object],
app_1     |         _header: 'GET /json/version HTTP/1.1\r\nhost: chrome:9222\r\naccept: application/json\r\nConnection: close\r\n\r\n',
app_1     |         _onPendingData: [Function: noopPendingOutput],
app_1     |         agent: [Object],
app_1     |         socketPath: undefined,
app_1     |         timeout: undefined,
app_1     |         method: 'GET',
app_1     |         path: '/json/version',
app_1     |         _ended: true,
app_1     |         res: [Circular],
app_1     |         aborted: undefined,
app_1     |         timeoutCb: null,
app_1     |         upgradeOrConnect: false,
app_1     |         parser: null,
app_1     |         maxHeadersCount: null,
app_1     |         [Symbol(outHeadersKey)]: [Object] },
app_1     |      request:
app_1     |       Request {
app_1     |         domain: null,
app_1     |         _events: [Object],
app_1     |         _eventsCount: 5,
app_1     |         _maxListeners: undefined,
app_1     |         uri: [Object],
app_1     |         resolveWithFullResponse: true,
app_1     |         readable: true,
app_1     |         writable: true,
app_1     |         _qs: [Object],
app_1     |         _auth: [Object],
app_1     |         _oauth: [Object],
app_1     |         _multipart: [Object],
app_1     |         _redirect: [Object],
app_1     |         _tunnel: [Object],
app_1     |         _rp_resolve: [Function],
app_1     |         _rp_reject: [Function],
app_1     |         _rp_promise: [Object],
app_1     |         _rp_callbackOrig: undefined,
app_1     |         callback: [Function],
app_1     |         _rp_options: [Object],
app_1     |         headers: [Object],
app_1     |         setHeader: [Function],
app_1     |         hasHeader: [Function],
app_1     |         getHeader: [Function],
app_1     |         removeHeader: [Function],
app_1     |         method: 'GET',
app_1     |         localAddress: undefined,
app_1     |         pool: {},
app_1     |         dests: [],
app_1     |         __isRequestRequest: true,
app_1     |         _callback: [Function: RP$callback],
app_1     |         proxy: null,
app_1     |         tunnel: false,
app_1     |         setHost: true,
app_1     |         originalCookieHeader: undefined,
app_1     |         _disableCookies: true,
app_1     |         _jar: undefined,
app_1     |         port: '9222',
app_1     |         host: 'chrome',
app_1     |         path: '/json/version',
app_1     |         _json: true,
app_1     |         httpModule: [Object],
app_1     |         agentClass: [Object],
app_1     |         agent: [Object],
app_1     |         _started: true,
app_1     |         href: 'http://chrome:9222/json/version',
app_1     |         req: [Object],
app_1     |         ntick: true,
app_1     |         response: [Circular],
app_1     |         originalHost: 'chrome:9222',
app_1     |         originalHostHeaderName: 'host',
app_1     |         responseContent: [Circular],
app_1     |         _destdata: true,
app_1     |         _ended: true,
app_1     |         _callbackCalled: true },
app_1     |      toJSON: [Function: responseToJSON],
app_1     |      caseless: Caseless { dict: [Object] },
app_1     |      read: [Function],
app_1     |      body: 'Host header is specified and is not an IP address or localhost.' } }
dockerizedpuppeteer_app_1 exited with code 0

Question

Does someone know what am I doing wrong?

Environment

  • Ubuntu 16.04
  • docker-compose version 1.18.0
@markxtji
Copy link

Hi guys, I ran into the same error .

@markxtji
Copy link

@hadrien-toma , please refer to this one :
OnetapInc/chromy#110

@junminstorage
Copy link

@markxtji I am new to docker, can you be more specific or provide working example? thanks!

@junminstorage
Copy link

I got it!
change the chrome/Dockerfile to:

FROM yukinying/chrome-headless-browser:65.0.3322.3
EXPOSE 9222
COPY entrypoint.sh .
RUN chmod +x ./entrypoint.sh
ENTRYPOINT ["/usr/local/bin/tini", "--", "./entrypoint.sh"]

@omidkrad
Copy link

Yes, it fails with this error:

(node:16) UnhandledPromiseRejectionWarning: StatusCodeError: 500 - "Host header is specified and is not an IP address or localhost."
    at new StatusCodeError (/app/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/app/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/app/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/app/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/app/node_modules/request/request.js:1157:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1079:12)
(node:16) 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:16) [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.

There seems to be a workaround for this issue here: puppeteer/issues/2242

@saumets
Copy link
Owner

saumets commented Aug 1, 2018

Thanks for reporting this. I am getting this too and will look to get it corrected shortly!

@saumets
Copy link
Owner

saumets commented Aug 4, 2018

I've added a workaround for this issue now until puppeteer / chromium team present a better solution.

If someone could please confirm this resolves the issue then I can close this, or let me know if the issue persists. Thanks.

@omidkrad
Copy link

omidkrad commented Aug 6, 2018

Yes, it works. Thanks!

@milesrichardson
Copy link

milesrichardson commented Feb 12, 2019

Another solution to this, if you want to avoid the extra JS dependencies, is to install nsutils, use dig to lookup the container IP before running the script, and pass something like $CHROME_IP as an environment variable.

e.g., in the app container (assuming it's based on debian/ubuntu),

...
RUN apt-get update -qq && apt-get install -yy curl dnsutils
CMD ["/bin/bash", "start.sh"]
# start.sh
#!/usr/bin/env bash

export CHROME_IP="$(dig +short chrome | tr -d '[[:space:]]')"

echo "CHROME_IP set to $CHROME_IP"

exec node run_tests.js

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

6 participants