ResponseParserError: Unable to parse response (no element found: line 1, column 0), invalid XML received:
See original GitHub issueI have a project using boto3
that spins up a number of EC2 instances and runs tests on them. When waiting for the instance to start, I often get the error in the title of this issue despite trying multiple methods of waiting for the instance.
Here’s a traceback using wait_until_running()
:
File "multitester.py", line 228, in block_until_instance_ready
booting_instance.wait_until_running()
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/factory.py", line 369, in do_waiter
waiter(self, *args, **kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/action.py", line 202, in __call__
response = waiter.wait(**params)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/waiter.py", line 53, in wait
Waiter.wait(self, **kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/waiter.py", line 297, in wait
response = self._operation_method(**kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/waiter.py", line 84, in __call__
return self._client_method(**kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 501, in _do_parse
root = self._parse_xml_string_to_dom(xml_contents)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 437, in _parse_xml_string_to_dom
"invalid XML received:\n%s" % (e, xml_string))
ResponseParserError: Unable to parse response (no element found: line 1, column 0), invalid XML received:
Here’s a traceback using reload()
(after which we manually check the instance state):
File "multitester.py", line 232, in block_until_instance_ready
booting_instance.reload()
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 501, in _do_parse
root = self._parse_xml_string_to_dom(xml_contents)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 437, in _parse_xml_string_to_dom
"invalid XML received:\n%s" % (e, xml_string))
ResponseParserError: Unable to parse response (no element found: line 1, column 0), invalid XML received:
We’ve even tried repeatedly creating new instance object using the instance ID at which point we sometimes hit this issue when trying to read the current state:
File "multitester.py", line 232, in block_until_instance_ready
_state = _instance.state['Name']
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/factory.py", line 339, in property_loader
self.load()
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/factory.py", line 505, in do_action
response = action(self, *args, **kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 135, in _send_request
request, operation_model, context)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 167, in _get_response
request, operation_model)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/endpoint.py", line 218, in _do_get_response
response_dict, operation_model.output_shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 242, in parse
parsed = self._do_parse(response, shape)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 501, in _do_parse
root = self._parse_xml_string_to_dom(xml_contents)
File "/path/to/my/venv/lib/python2.7/site-packages/botocore/parsers.py", line 437, in _parse_xml_string_to_dom
"invalid XML received:\n%s" % (e, xml_string))
ResponseParserError: Unable to parse response (no element found: line 1, column 0), invalid XML received:
Unfortunately, I’m not sure how to reliably produce this. The code often works just fine but I’d say ~2% of the time we hit this error.
The Python version being used is 2.7.16 and the installed packages that boto3
depends on are:
boto3==1.9.145
botocore==1.12.145
docutils==0.14
futures==3.2.0
jmespath==0.9.4
python-dateutil==2.8.0
s3transfer==0.2.0
six==1.12.0
urllib3==1.24.3
Any help fixing this or even suggesting a workaround for us in the meantime would be greatly appreciated! It looks like I’m not the only one who has his this according to https://github.com/boto/boto3/issues/717.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
Top GitHub Comments
I may have figured this out. Our code was sharing a session and EC2 resource between processes. I have yet to see this problem after giving each process its own instance so feel free to close this if you like.
Hi @amitainz, that’s correct. Both
Session
andResource
are NOT thread or multi-process safe. We recommend creating a separate instance per parallelization primitive.You can find more information here: Session Resource