Fixing issues with bytes vs unicode for hmac
This commit is contained in:
parent
4e82409cc1
commit
1941d8bfb2
@ -26,6 +26,7 @@ from builtins import * # noqa
|
|||||||
import requests
|
import requests
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import json
|
import json
|
||||||
|
from future.utils import native
|
||||||
from base64 import b64decode, b64encode
|
from base64 import b64decode, b64encode
|
||||||
from retries import retries
|
from retries import retries
|
||||||
from requests_futures.sessions import FuturesSession
|
from requests_futures.sessions import FuturesSession
|
||||||
@ -137,11 +138,11 @@ class BaseRequest( object ):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _ExtraHeaders( method, request_uri, request_body = None ):
|
def _ExtraHeaders( method, request_uri, request_body = None ):
|
||||||
if not request_body:
|
if not request_body:
|
||||||
request_body = ''
|
request_body = bytes( b'' )
|
||||||
headers = dict( _HEADERS )
|
headers = dict( _HEADERS )
|
||||||
headers[ _HMAC_HEADER ] = b64encode(
|
headers[ _HMAC_HEADER ] = b64encode(
|
||||||
CreateRequestHmac( method,
|
CreateRequestHmac( ToBytes( method ),
|
||||||
urllib.parse.urlparse( request_uri ).path,
|
ToBytes( urllib.parse.urlparse( request_uri ).path ),
|
||||||
request_body,
|
request_body,
|
||||||
BaseRequest.hmac_secret ) )
|
BaseRequest.hmac_secret ) )
|
||||||
return headers
|
return headers
|
||||||
@ -204,7 +205,8 @@ def _ValidateResponseObject( response ):
|
|||||||
|
|
||||||
|
|
||||||
def _BuildUri( handler ):
|
def _BuildUri( handler ):
|
||||||
return urllib.parse.urljoin( BaseRequest.server_location, handler )
|
return native( ToBytes( urllib.parse.urljoin( BaseRequest.server_location,
|
||||||
|
handler ) ) )
|
||||||
|
|
||||||
|
|
||||||
SERVER_HEALTHY = False
|
SERVER_HEALTHY = False
|
||||||
@ -216,7 +218,7 @@ def _CheckServerIsHealthyWithCache():
|
|||||||
request_uri = _BuildUri( 'healthy' )
|
request_uri = _BuildUri( 'healthy' )
|
||||||
response = requests.get( request_uri,
|
response = requests.get( request_uri,
|
||||||
headers = BaseRequest._ExtraHeaders(
|
headers = BaseRequest._ExtraHeaders(
|
||||||
'GET', request_uri, '' ) )
|
'GET', request_uri, bytes( b'' ) ) )
|
||||||
_ValidateResponseObject( response )
|
_ValidateResponseObject( response )
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
Loading…
Reference in New Issue
Block a user