Skip to content

Commit 37b563f

Browse files
committed
Handle responses from servers that do not specify the content-type.
1 parent c805ace commit 37b563f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import urlparse as parse
2929

3030
from .command import Command
31+
from .errorhandler import ErrorCode
3132
from . import utils
3233

3334
LOGGER = logging.getLogger(__name__)
@@ -397,9 +398,17 @@ def _request(self, url, data=None, method=None):
397398
if response.code > 399 and response.code < 500:
398399
return {'status': response.code, 'value': response.read()}
399400
body = response.read().decode('utf-8').replace('\x00', '').strip()
400-
content_type = response.info()['Content-Type'] or []
401-
if 'application/json' in content_type:
402-
data = utils.load_json(body.strip())
401+
content_type = response.info().getheaders('Content-Type')
402+
if not any([x.startswith('image/png') for x in content_type]):
403+
try:
404+
data = utils.load_json(body.strip())
405+
except ValueError:
406+
if response.code > 199 and response.code < 300:
407+
status = ErrorCode.SUCCESS
408+
else:
409+
status = ErrorCode.UNKNOWN_ERROR
410+
return {'status': status, 'value': body.strip()}
411+
403412
assert type(data) is dict, (
404413
'Invalid server response body: %s' % body)
405414
assert 'status' in data, (
@@ -409,7 +418,7 @@ def _request(self, url, data=None, method=None):
409418
if 'value' not in data:
410419
data['value'] = None
411420
return data
412-
elif 'image/png' in content_type:
421+
else:
413422
data = {'status': 0, 'value': body.strip()}
414423
return data
415424
finally:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy