Advertisement
frisco82

PGOApi Hash Fix

Jul 5th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.88 KB | None | 0 0
  1. --- a/pgoapi/hash_server.py
  2. +++ b/pgoapi/hash_server.py
  3. @@ -38,29 +38,35 @@ class HashServer(HashEngine):
  4.              'Requests': [base64.b64encode(x.SerializeToString()).decode('ascii') for x in requestslist]
  5.          }
  6.  
  7. -        # request hashes from hashing server
  8. -        try:
  9. -            response = self._session.post(self.endpoint, json=payload, headers=self.headers, timeout=30)
  10. -        except requests.exceptions.Timeout:
  11. -            raise HashingTimeoutException('Hashing request timed out.')
  12. -        except requests.exceptions.ConnectionError as error:
  13. -            raise HashingOfflineException(error)
  14. +        for x in range (0, 5):
  15. +            # request hashes from hashing server
  16. +            try:
  17. +                response = self._session.post(self.endpoint, json=payload, headers=self.headers, timeout=30)
  18. +            except requests.exceptions.Timeout:
  19. +                continue
  20. +                # raise HashingTimeoutException('Hashing request timed out.')
  21. +            except requests.exceptions.ConnectionError as error:
  22. +                continue
  23. +                # raise HashingOfflineException(error)
  24. +
  25. +            if response.status_code == 400:
  26. +                continue
  27. +                # raise BadHashRequestException("400: Bad request, error: {}".format(response.text))
  28. +            elif response.status_code == 403:
  29. +                raise TempHashingBanException('Your IP was temporarily banned for sending too many requests with invalid keys')
  30. +            elif response.status_code == 429:
  31. +                raise HashingQuotaExceededException("429: Request limited, error: {}".format(response.text))
  32. +            elif response.status_code in (502, 503, 504):
  33. +                raise HashingOfflineException('{} Server Error'.format(response.status_code))
  34. +            elif response.status_code != 200:
  35. +                error = 'Unexpected HTTP server response - needs 200 got {c}. {t}'.format(
  36. +                    c=response.status_code, t=response.text)
  37. +                raise UnexpectedHashResponseException(error)
  38.  
  39. -        if response.status_code == 400:
  40. -            raise BadHashRequestException("400: Bad request, error: {}".format(response.text))
  41. -        elif response.status_code == 403:
  42. -            raise TempHashingBanException('Your IP was temporarily banned for sending too many requests with invalid keys')
  43. -        elif response.status_code == 429:
  44. -            raise HashingQuotaExceededException("429: Request limited, error: {}".format(response.text))
  45. -        elif response.status_code in (502, 503, 504):
  46. -            raise HashingOfflineException('{} Server Error'.format(response.status_code))
  47. -        elif response.status_code != 200:
  48. -            error = 'Unexpected HTTP server response - needs 200 got {c}. {t}'.format(
  49. -                c=response.status_code, t=response.text)
  50. -            raise UnexpectedHashResponseException(error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement