prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [Dev] local variable 'unexpected_reponse_retry' referenced before assignment
  There is a typo in a variable
  
  `unexpected_reponse_retry` should be `unexpected_response_retry`
  /pokemongo_bot/api_wrapper.py - line 120 
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pokemongo_bot/api_wrapper.py`
  Content:
  ```
  1 import time
  2 
  3 from pgoapi.exceptions import (ServerSideRequestThrottlingException,
  4     NotLoggedInException, ServerBusyOrOfflineException,
  5     NoPlayerPositionSetException, EmptySubrequestChainException,
  6     UnexpectedResponseException)
  7 from pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi
  8 from pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType
  9 
  10 import pokemongo_bot.logger as logger
  11 from human_behaviour import sleep
  12 
  13 class ApiWrapper(PGoApi):
  14     def __init__(self):
  15         PGoApi.__init__(self)
  16         self.useVanillaRequest = False
  17 
  18     def create_request(self):
  19         RequestClass = ApiRequest
  20         if self.useVanillaRequest:
  21             RequestClass = PGoApiRequest
  22 
  23         return RequestClass(
  24             self._api_endpoint,
  25             self._auth_provider,
  26             self._position_lat,
  27             self._position_lng,
  28             self._position_alt
  29         )
  30 
  31     def login(self, *args):
  32         # login needs base class "create_request"
  33         self.useVanillaRequest = True
  34         try:
  35             ret_value = PGoApi.login(self, *args)
  36         finally:
  37             # cleanup code
  38             self.useVanillaRequest = False
  39         return ret_value
  40 
  41 
  42 class ApiRequest(PGoApiRequest):
  43     def __init__(self, *args):
  44         PGoApiRequest.__init__(self, *args)
  45         self.request_callers = []
  46         self.last_api_request_time = None
  47         self.requests_per_seconds = 2
  48 
  49     def can_call(self):
  50         if not self._req_method_list:
  51             raise EmptySubrequestChainException()
  52 
  53         if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):
  54             raise NoPlayerPositionSetException()
  55 
  56         if self._auth_provider is None or not self._auth_provider.is_login():
  57             self.log.info('Not logged in')
  58             raise NotLoggedInException()
  59 
  60         return True
  61 
  62     def _call(self):
  63         return PGoApiRequest.call(self)
  64 
  65     def _pop_request_callers(self):
  66         r = self.request_callers
  67         self.request_callers = []
  68         return [i.upper() for i in r]
  69 
  70     def is_response_valid(self, result, request_callers):
  71         if not result or result is None or not isinstance(result, dict):
  72             return False
  73 
  74         if not 'responses' in result or not 'status_code' in result:
  75             return False
  76 
  77         if not isinstance(result['responses'], dict):
  78             return False
  79 
  80         # the response can still programatically be valid at this point
  81         # but still be wrong. we need to check if the server did sent what we asked it
  82         for request_caller in request_callers:
  83             if not request_caller in result['responses']:
  84                 return False
  85 
  86         return True
  87 
  88     def call(self, max_retry=15):
  89         request_callers = self._pop_request_callers()
  90         if not self.can_call():
  91             return False # currently this is never ran, exceptions are raised before
  92 
  93         request_timestamp = None
  94         api_req_method_list = self._req_method_list
  95         result = None
  96         try_cnt = 0
  97         throttling_retry = 0
  98         unexpected_response_retry = 0
  99         while True:
  100             request_timestamp = self.throttle_sleep()
  101             # self._call internally clear this field, so save it
  102             self._req_method_list = [req_method for req_method in api_req_method_list]
  103             try:
  104                 result = self._call()
  105                 should_throttle_retry = False
  106                 should_unexpected_response_retry = False
  107             except ServerSideRequestThrottlingException:
  108                 should_throttle_retry = True
  109             except UnexpectedResponseException:
  110                 should_unexpected_response_retry = True
  111 
  112             if should_throttle_retry:
  113                 throttling_retry += 1
  114                 if throttling_retry >= max_retry:
  115                     raise ServerSideRequestThrottlingException('Server throttled too many times')
  116                 sleep(1) # huge sleep ?
  117                 continue # skip response checking
  118 
  119             if should_unexpected_response_retry:
  120                 unexpected_reponse_retry += 1
  121                 if unexpected_response_retry >= 5:
  122                     logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')
  123                     sleep(30)
  124                 else:
  125                     sleep(2)
  126                 continue
  127                 
  128             if not self.is_response_valid(result, request_callers):
  129                 try_cnt += 1
  130                 if try_cnt > 3:
  131                     logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')
  132                 if try_cnt >= max_retry:
  133                     raise ServerBusyOrOfflineException()
  134                 sleep(1)
  135             else:
  136                 break
  137 
  138         self.last_api_request_time = request_timestamp
  139         return result
  140 
  141     def __getattr__(self, func):
  142         if func.upper() in  RequestType.keys():
  143             self.request_callers.append(func)
  144         return PGoApiRequest.__getattr__(self, func)
  145 
  146     def throttle_sleep(self):
  147         now_milliseconds = time.time() * 1000
  148         required_delay_between_requests = 1000 / self.requests_per_seconds
  149 
  150         difference = now_milliseconds - (self.last_api_request_time if self.last_api_request_time else 0)
  151 
  152         if self.last_api_request_time != None and difference < required_delay_between_requests:
  153             sleep_time = required_delay_between_requests - difference
  154             time.sleep(sleep_time / 1000)
  155 
  156         return now_milliseconds
  157
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py
  --- a/pokemongo_bot/api_wrapper.py
  +++ b/pokemongo_bot/api_wrapper.py
  @@ -117,7 +117,7 @@
                   continue # skip response checking
   
               if should_unexpected_response_retry:
  -                unexpected_reponse_retry += 1
  +                unexpected_response_retry += 1
                   if unexpected_response_retry >= 5:
                       logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')
                       sleep(30)
  
verification_info: {"golden_diff": "diff --git a/pokemongo_bot/api_wrapper.py b/pokemongo_bot/api_wrapper.py\n--- a/pokemongo_bot/api_wrapper.py\n+++ b/pokemongo_bot/api_wrapper.py\n@@ -117,7 +117,7 @@\n                 continue # skip response checking\n \n             if should_unexpected_response_retry:\n-                unexpected_reponse_retry += 1\n+                unexpected_response_retry += 1\n                 if unexpected_response_retry >= 5:\n                     logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')\n                     sleep(30)\n", "issue": "[Dev] local variable 'unexpected_reponse_retry' referenced before assignment\nThere is a typo in a variable\n\n`unexpected_reponse_retry` should be `unexpected_response_retry`\n/pokemongo_bot/api_wrapper.py - line 120 \n\n", "before_files": [{"content": "import time\n\nfrom pgoapi.exceptions import (ServerSideRequestThrottlingException,\n    NotLoggedInException, ServerBusyOrOfflineException,\n    NoPlayerPositionSetException, EmptySubrequestChainException,\n    UnexpectedResponseException)\nfrom pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi\nfrom pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType\n\nimport pokemongo_bot.logger as logger\nfrom human_behaviour import sleep\n\nclass ApiWrapper(PGoApi):\n    def __init__(self):\n        PGoApi.__init__(self)\n        self.useVanillaRequest = False\n\n    def create_request(self):\n        RequestClass = ApiRequest\n        if self.useVanillaRequest:\n            RequestClass = PGoApiRequest\n\n        return RequestClass(\n            self._api_endpoint,\n            self._auth_provider,\n            self._position_lat,\n            self._position_lng,\n            self._position_alt\n        )\n\n    def login(self, *args):\n        # login needs base class \"create_request\"\n        self.useVanillaRequest = True\n        try:\n            ret_value = PGoApi.login(self, *args)\n        finally:\n            # cleanup code\n            self.useVanillaRequest = False\n        return ret_value\n\n\nclass ApiRequest(PGoApiRequest):\n    def __init__(self, *args):\n        PGoApiRequest.__init__(self, *args)\n        self.request_callers = []\n        self.last_api_request_time = None\n        self.requests_per_seconds = 2\n\n    def can_call(self):\n        if not self._req_method_list:\n            raise EmptySubrequestChainException()\n\n        if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):\n            raise NoPlayerPositionSetException()\n\n        if self._auth_provider is None or not self._auth_provider.is_login():\n            self.log.info('Not logged in')\n            raise NotLoggedInException()\n\n        return True\n\n    def _call(self):\n        return PGoApiRequest.call(self)\n\n    def _pop_request_callers(self):\n        r = self.request_callers\n        self.request_callers = []\n        return [i.upper() for i in r]\n\n    def is_response_valid(self, result, request_callers):\n        if not result or result is None or not isinstance(result, dict):\n            return False\n\n        if not 'responses' in result or not 'status_code' in result:\n            return False\n\n        if not isinstance(result['responses'], dict):\n            return False\n\n        # the response can still programatically be valid at this point\n        # but still be wrong. we need to check if the server did sent what we asked it\n        for request_caller in request_callers:\n            if not request_caller in result['responses']:\n                return False\n\n        return True\n\n    def call(self, max_retry=15):\n        request_callers = self._pop_request_callers()\n        if not self.can_call():\n            return False # currently this is never ran, exceptions are raised before\n\n        request_timestamp = None\n        api_req_method_list = self._req_method_list\n        result = None\n        try_cnt = 0\n        throttling_retry = 0\n        unexpected_response_retry = 0\n        while True:\n            request_timestamp = self.throttle_sleep()\n            # self._call internally clear this field, so save it\n            self._req_method_list = [req_method for req_method in api_req_method_list]\n            try:\n                result = self._call()\n                should_throttle_retry = False\n                should_unexpected_response_retry = False\n            except ServerSideRequestThrottlingException:\n                should_throttle_retry = True\n            except UnexpectedResponseException:\n                should_unexpected_response_retry = True\n\n            if should_throttle_retry:\n                throttling_retry += 1\n                if throttling_retry >= max_retry:\n                    raise ServerSideRequestThrottlingException('Server throttled too many times')\n                sleep(1) # huge sleep ?\n                continue # skip response checking\n\n            if should_unexpected_response_retry:\n                unexpected_reponse_retry += 1\n                if unexpected_response_retry >= 5:\n                    logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')\n                    sleep(30)\n                else:\n                    sleep(2)\n                continue\n                \n            if not self.is_response_valid(result, request_callers):\n                try_cnt += 1\n                if try_cnt > 3:\n                    logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')\n                if try_cnt >= max_retry:\n                    raise ServerBusyOrOfflineException()\n                sleep(1)\n            else:\n                break\n\n        self.last_api_request_time = request_timestamp\n        return result\n\n    def __getattr__(self, func):\n        if func.upper() in  RequestType.keys():\n            self.request_callers.append(func)\n        return PGoApiRequest.__getattr__(self, func)\n\n    def throttle_sleep(self):\n        now_milliseconds = time.time() * 1000\n        required_delay_between_requests = 1000 / self.requests_per_seconds\n\n        difference = now_milliseconds - (self.last_api_request_time if self.last_api_request_time else 0)\n\n        if self.last_api_request_time != None and difference < required_delay_between_requests:\n            sleep_time = required_delay_between_requests - difference\n            time.sleep(sleep_time / 1000)\n\n        return now_milliseconds\n", "path": "pokemongo_bot/api_wrapper.py"}], "after_files": [{"content": "import time\n\nfrom pgoapi.exceptions import (ServerSideRequestThrottlingException,\n    NotLoggedInException, ServerBusyOrOfflineException,\n    NoPlayerPositionSetException, EmptySubrequestChainException,\n    UnexpectedResponseException)\nfrom pgoapi.pgoapi import PGoApi, PGoApiRequest, RpcApi\nfrom pgoapi.protos.POGOProtos.Networking.Requests_pb2 import RequestType\n\nimport pokemongo_bot.logger as logger\nfrom human_behaviour import sleep\n\nclass ApiWrapper(PGoApi):\n    def __init__(self):\n        PGoApi.__init__(self)\n        self.useVanillaRequest = False\n\n    def create_request(self):\n        RequestClass = ApiRequest\n        if self.useVanillaRequest:\n            RequestClass = PGoApiRequest\n\n        return RequestClass(\n            self._api_endpoint,\n            self._auth_provider,\n            self._position_lat,\n            self._position_lng,\n            self._position_alt\n        )\n\n    def login(self, *args):\n        # login needs base class \"create_request\"\n        self.useVanillaRequest = True\n        try:\n            ret_value = PGoApi.login(self, *args)\n        finally:\n            # cleanup code\n            self.useVanillaRequest = False\n        return ret_value\n\n\nclass ApiRequest(PGoApiRequest):\n    def __init__(self, *args):\n        PGoApiRequest.__init__(self, *args)\n        self.request_callers = []\n        self.last_api_request_time = None\n        self.requests_per_seconds = 2\n\n    def can_call(self):\n        if not self._req_method_list:\n            raise EmptySubrequestChainException()\n\n        if (self._position_lat is None) or (self._position_lng is None) or (self._position_alt is None):\n            raise NoPlayerPositionSetException()\n\n        if self._auth_provider is None or not self._auth_provider.is_login():\n            self.log.info('Not logged in')\n            raise NotLoggedInException()\n\n        return True\n\n    def _call(self):\n        return PGoApiRequest.call(self)\n\n    def _pop_request_callers(self):\n        r = self.request_callers\n        self.request_callers = []\n        return [i.upper() for i in r]\n\n    def is_response_valid(self, result, request_callers):\n        if not result or result is None or not isinstance(result, dict):\n            return False\n\n        if not 'responses' in result or not 'status_code' in result:\n            return False\n\n        if not isinstance(result['responses'], dict):\n            return False\n\n        # the response can still programatically be valid at this point\n        # but still be wrong. we need to check if the server did sent what we asked it\n        for request_caller in request_callers:\n            if not request_caller in result['responses']:\n                return False\n\n        return True\n\n    def call(self, max_retry=15):\n        request_callers = self._pop_request_callers()\n        if not self.can_call():\n            return False # currently this is never ran, exceptions are raised before\n\n        request_timestamp = None\n        api_req_method_list = self._req_method_list\n        result = None\n        try_cnt = 0\n        throttling_retry = 0\n        unexpected_response_retry = 0\n        while True:\n            request_timestamp = self.throttle_sleep()\n            # self._call internally clear this field, so save it\n            self._req_method_list = [req_method for req_method in api_req_method_list]\n            try:\n                result = self._call()\n                should_throttle_retry = False\n                should_unexpected_response_retry = False\n            except ServerSideRequestThrottlingException:\n                should_throttle_retry = True\n            except UnexpectedResponseException:\n                should_unexpected_response_retry = True\n\n            if should_throttle_retry:\n                throttling_retry += 1\n                if throttling_retry >= max_retry:\n                    raise ServerSideRequestThrottlingException('Server throttled too many times')\n                sleep(1) # huge sleep ?\n                continue # skip response checking\n\n            if should_unexpected_response_retry:\n                unexpected_response_retry += 1\n                if unexpected_response_retry >= 5:\n                    logger.log('Server is not responding correctly to our requests.  Waiting for 30 seconds to reconnect.', 'red')\n                    sleep(30)\n                else:\n                    sleep(2)\n                continue\n                \n            if not self.is_response_valid(result, request_callers):\n                try_cnt += 1\n                if try_cnt > 3:\n                    logger.log('Server seems to be busy or offline - try again - {}/{}'.format(try_cnt, max_retry), 'red')\n                if try_cnt >= max_retry:\n                    raise ServerBusyOrOfflineException()\n                sleep(1)\n            else:\n                break\n\n        self.last_api_request_time = request_timestamp\n        return result\n\n    def __getattr__(self, func):\n        if func.upper() in  RequestType.keys():\n            self.request_callers.append(func)\n        return PGoApiRequest.__getattr__(self, func)\n\n    def throttle_sleep(self):\n        now_milliseconds = time.time() * 1000\n        required_delay_between_requests = 1000 / self.requests_per_seconds\n\n        difference = now_milliseconds - (self.last_api_request_time if self.last_api_request_time else 0)\n\n        if self.last_api_request_time != None and difference < required_delay_between_requests:\n            sleep_time = required_delay_between_requests - difference\n            time.sleep(sleep_time / 1000)\n\n        return now_milliseconds\n", "path": "pokemongo_bot/api_wrapper.py"}]}