Skip to content

Commit 86ee772

Browse files
symonkdiemol
andauthored
[py] Add debug logging for urllib response data (#10568)
* debug urllib response status, decoded data and headers * use `python3.7` compliant f-strings Co-authored-by: Diego Molina <[email protected]>
1 parent fbef19e commit 86ee772

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -347,34 +347,34 @@ def _request(self, method, url, body=None):
347347
LOGGER.debug(f"{method} {url} {body}")
348348
parsed_url = parse.urlparse(url)
349349
headers = self.get_remote_connection_headers(parsed_url, self.keep_alive)
350-
resp = None
351-
if body and method != 'POST' and method != 'PUT':
350+
response = None
351+
if body and method not in ("POST", "PUT"):
352352
body = None
353353

354354
if self.keep_alive:
355-
resp = self._conn.request(method, url, body=body, headers=headers)
356-
statuscode = resp.status
355+
response = self._conn.request(method, url, body=body, headers=headers)
356+
statuscode = response.status
357357
else:
358358
conn = self._get_connection_manager()
359359
with conn as http:
360-
resp = http.request(method, url, body=body, headers=headers)
361-
362-
statuscode = resp.status
363-
if not hasattr(resp, 'getheader'):
364-
if hasattr(resp.headers, 'getheader'):
365-
resp.getheader = lambda x: resp.headers.getheader(x)
366-
elif hasattr(resp.headers, 'get'):
367-
resp.getheader = lambda x: resp.headers.get(x)
368-
369-
data = resp.data.decode('UTF-8')
360+
response = http.request(method, url, body=body, headers=headers)
361+
362+
statuscode = response.status
363+
if not hasattr(response, 'getheader'):
364+
if hasattr(response.headers, 'getheader'):
365+
response.getheader = lambda x: response.headers.getheader(x)
366+
elif hasattr(response.headers, 'get'):
367+
response.getheader = lambda x: response.headers.get(x)
368+
data = response.data.decode('UTF-8')
369+
LOGGER.debug(f"Remote response: status={response.status} | data={data} | headers={response.headers}")
370370
try:
371371
if 300 <= statuscode < 304:
372-
return self._request('GET', resp.getheader('location'))
372+
return self._request('GET', response.getheader('location'))
373373
if 399 < statuscode <= 500:
374374
return {'status': statuscode, 'value': data}
375375
content_type = []
376-
if resp.getheader('Content-Type'):
377-
content_type = resp.getheader('Content-Type').split(';')
376+
if response.getheader('Content-Type'):
377+
content_type = response.getheader('Content-Type').split(';')
378378
if not any([x.startswith('image/png') for x in content_type]):
379379

380380
try:
@@ -386,7 +386,7 @@ def _request(self, method, url, body=None):
386386
status = ErrorCode.UNKNOWN_ERROR
387387
return {'status': status, 'value': data.strip()}
388388

389-
# Some of the drivers incorrectly return a response
389+
# Some drivers incorrectly return a response
390390
# with no 'value' field when they should return null.
391391
if 'value' not in data:
392392
data['value'] = None
@@ -396,7 +396,7 @@ def _request(self, method, url, body=None):
396396
return data
397397
finally:
398398
LOGGER.debug("Finished Request")
399-
resp.close()
399+
response.close()
400400

401401
def close(self):
402402
"""

0 commit comments

Comments
 (0)