title: Unexpected type-error python
body: <p>I am trying to create a client used to mainly test out the responses of a server asynchronously. I have created a function that basically waits for the next response from the server, if a requestId is provided when this function is called it will look for the next response with the requestId provided. Here is the function:</p>
  
  <pre><code>def getNextResponse(self, requestId = None):
      logger = logging.getLogger(__name__)
      self.acknowledge += 1
      logger.info("requestId ack for this response: {}".format(requestId))
      while(not self.response):
          pass
      self.acknowledge -= 1
      logger.info("requestId unset for this response: {}".format(requestId))
      message = json.loads(self.messagesList[len(self.messagesList)-1])
  
      if(requestId != None):
          while(requestId != message['body']['requestId']):
              self.acknowledge += 1
              while(not self.response):
                  pass    
              self.acknowledge -= 1
              message = self.messagesList[len(self.messagesList)-1]
  
      self.startMonitor -= 1       
      return message['body']
  </code></pre>
  
  <p>I also have helper functions for each command which can be sent to the engine below is one of said helper function for a ping command:</p>
  
  <pre><code> def ping(self, sessionId = None, requestId = None, version="1.0"):
      result = {
          "method": "Ping"
          }
      if(None != version):
          result['version'] = version
      if(None != sessionId):
          result['sessionId'] = sessionId
      if(None != requestId):
          result['requestId'] = requestId
      logger = logging.getLogger(__name__)
      logger.info("Message Sent: " + json.dumps(result, indent=4))
      self.startMonitor += 1
      self.ws.send(json.dumps(result))
      message = self.getNextResponse(requestId = requestId)
  
      return message
  </code></pre>
  
  <p>It basically sets up a json object which contains all the parameters that the server expects and then sends the entire json message to the server. After it has been sent i call getNextResponse to await a response from the server. The requestId is set to None by default, so if no requestId is provided, it will just look for the very next response returned by the server. Since this can be quite inconsistent because of other asynchronous commands, one can provided a unique requestId for the command so that the response from the server will also contain this requestId thus making each response unique. </p>
  
  <p>In my test case I am generating a random requestId by using:</p>
  
  <pre><code>def genRequestId(self):
      x = random.randint(10000000, 99999999)
      print x
      reqId = str(x)+"-97a2-11e6-9346-fde5d2234523"
      return reqId  
  </code></pre>
  
  <p>The problem that I encountered is that sometimes (seems to be random), when I call ping in one of my test cases, i get this error:</p>
  
  <pre><code>message = self.getNextResponse(requestId = requestId)
  TypeError: string indices must be integers, not str
  </code></pre>
  
  <p>I am quite confused by this error, requestId that I am generating inside ping is supposed to be a string and I am not referencing inside it in any way. I have tried removing the reference to the parameter like so:</p>
  
  <pre><code>message = self.getNextResponse(requestId)
  </code></pre>
  
  <p>But I am still getting this error. The error doesn't go any deeper inside the getNextResponse function which leads me to believe that it is coming from inside the ping function when I try to call it. Any help would be greatly appreciated!</p>
  
  <p>EDIT: Here is the error</p>
  
  <p>Traceback (most recent call last):
  File "ctetest./RegressionTest/WebsocketTest\test_18_RecTimer.py", line                     385, in test009_recTimer_Start_withAudio
      response = client.endSession(sessionId = sessionId, requestId = requestId_2)</p>
  
  <p>File "ctetest./RegressionTest/WebsocketTest../.././CTESetupClass\WebsocketCl
  ient.py", line 528, in endSession
      message = self.getNextResponse(requestId)
    File "ctetest./RegressionTest/WebsocketTest../.././CTESetupClass\WebsocketCl
  ient.py", line 49, in wrapper
      raise ret
  TypeError: string indices must be integers, not str </p>