miasmos / op.gg-api

Serves op.gg web pages as json.
MIT License
81 stars 21 forks source link

RequestError: TypeError: The header content contains invalid characters #12

Closed twardle closed 7 years ago

twardle commented 7 years ago

So, I'm thinking I'm getting this error:

{ RequestError: TypeError: The header content contains invalid characters
    at new RequestError (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\errors.js:14:15)
    at Request.plumbing.callback (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:87:29)
    at Request.RP$callback [as _callback] (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:188:22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:757:10)
    at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
    at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
    at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
  name: 'RequestError',
  message: 'TypeError: The header content contains invalid characters',
  cause: 
   TypeError: The header content contains invalid characters
       at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:360:11)
       at new ClientRequest (_http_client.js:85:14)
       at Object.exports.request (http.js:31:10)
       at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:755:32)
       at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
       at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
       at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
       at runCallback (timers.js:672:20)
       at tryOnImmediate (timers.js:645:5)
       at processImmediate [as _immediateCallback] (timers.js:617:5),
  error: 
   TypeError: The header content contains invalid characters
       at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:360:11)
       at new ClientRequest (_http_client.js:85:14)
       at Object.exports.request (http.js:31:10)
       at Request.start (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:755:32)
       at Request.end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:1525:10)
       at end (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:567:14)
       at Immediate.<anonymous> (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:581:7)
       at runCallback (timers.js:672:20)
       at tryOnImmediate (timers.js:645:5)
       at processImmediate [as _immediateCallback] (timers.js:617:5),
  options: 
   { headers: 
      { 'Content-Type': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
        'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6' },
     uri: 'http://na.op.gg/summoner/?userName=LëëŠin&',
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response: undefined }

Whenever a summoner name includes a special character, i.e. "ƒiøra"

While Riot doesn't allow new users to create names with special characters, many long term users are still allowed to have these characters in their names until they do a name change. These users definitely exist and I can look them up with the special characters in their name on op.gg without any issues. Any ideas what might be causing this, or is this just a validation check in the API that corresponds to Riot's new naming conventions?

twardle commented 7 years ago

Everything seems to be working perfectly now. Not getting any errors, I'll let you know if I run into anything else but thank you very much for all quick responses and fixes.

miasmos commented 7 years ago

No problem. Enjoy.

On Mon, May 15, 2017 at 3:10 PM, twardle notifications@github.com wrote:

Everything seems to be working perfectly now. Not getting any errors, I'll let you know if I run into anything else but thank you very much for all quick responses and fixes.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/stephenpoole/op.gg-api/issues/12#issuecomment-301573999, or mute the thread https://github.com/notifications/unsubscribe-auth/ADMHH2CJSZz_qKC9hHtdP-Tz89lj8ncJks5r6KMPgaJpZM4NbgjM .

twardle commented 7 years ago

I have a question, but what is the best way to wait for a response from your API? I'm new to javascript, so I've been trying to do research on appropriately using callbacks to appropriately handle errors and resending requests that time out. Generally, this only happens when I attempt to send more than 500 requests.

{ RequestError: Error: connect ETIMEDOUT 54.175.33.199:80
    at new RequestError (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\errors.js:14:15)
    at Request.plumbing.callback (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:87:29)
    at Request.RP$callback [as _callback] (C:\Users\Tyler\workspace\javascript\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:188:22)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at Request.onRequestError (C:\Users\Tyler\workspace\javascript\node_modules\request\request.js:884:8)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:309:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1277:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  name: 'RequestError',
  message: 'Error: connect ETIMEDOUT 54.175.33.199:80',
  cause: 
   { Error: connect ETIMEDOUT 54.175.33.199:80
       at Object.exports._errnoException (util.js:1018:11)
       at exports._exceptionWithHostPort (util.js:1041:20)
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
     code: 'ETIMEDOUT',
     errno: 'ETIMEDOUT',
     syscall: 'connect',
     address: '54.175.33.199',
     port: 80 },
  error: 
   { Error: connect ETIMEDOUT 54.175.33.199:80
       at Object.exports._errnoException (util.js:1018:11)
       at exports._exceptionWithHostPort (util.js:1041:20)
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
     code: 'ETIMEDOUT',
     errno: 'ETIMEDOUT',
     syscall: 'connect',
     address: '54.175.33.199',
     port: 80 },
  options: 
   { headers: 
      { 'Content-Type': 'text/html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
        'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6' },
     uri: 'http://na.op.gg/summoner/?userName=HoneyDewMelons&',
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response: undefined }

This is the actual error that I'm receiving and I'm under the assumption it has to do with the volume of requests I'm sending without getting a response. I've attempted to bodge a solution by just adding a wait function; however, this doesn't do anything other than just bog down the code (expected this, but it was worth a shot).

miasmos commented 7 years ago

This is outside the scope of this project, but I can point you in the right direction. Generally, you want to use a limiter of some sort. Many exist, but the one I usually use is here: https://www.npmjs.com/package/bottleneck

Make sure you're handling errors gracefully as well, as a request can sometimes fail even if you're not being rate limited.

twardle commented 7 years ago

Thanks, that's all I was looking for.