MCPcopy
hub / github.com/scrapinghub/splash / get_response_body_bytes

Function get_response_body_bytes

splash/har/utils.py:33–47  ·  view source on GitHub ↗

Return binary response data

(har_response)

Source from the content-addressed store, hash-verified

31
32
33def get_response_body_bytes(har_response):
34 """ Return binary response data """
35 content = har_response['content']
36 body = content.get('text', None)
37 if body is None:
38 return None
39 encoding = content.get('encoding', None)
40 if encoding == 'base64':
41 return base64.b64decode(body)
42 if encoding is None or encoding == 'binary':
43 if not isinstance(body, bytes):
44 return body.encode('utf8')
45 return body
46 else:
47 raise ValueError("Unsupported HAR content encoding: %r" % encoding)

Callers 10

_get_body_objectMethod · 0.90
test_headersMethod · 0.90
test_redirects_followMethod · 0.90
test_postMethod · 0.90
assertBase64ContentMethod · 0.90
test_get_body_bytesFunction · 0.90

Calls 1

getMethod · 0.45

Tested by 9

test_headersMethod · 0.72
test_redirects_followMethod · 0.72
test_postMethod · 0.72
assertBase64ContentMethod · 0.72
test_get_body_bytesFunction · 0.72