question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResponseParserError: Unable to parse response (no element found: line 1, column 0), invalid XML received:

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bmwcommented, May 13, 2019

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.

1reaction
nateprewittcommented, Nov 11, 2021

Hi @amitainz, that’s correct. Both Session and Resource are NOT thread or multi-process safe. We recommend creating a separate instance per parallelization primitive.

You can find more information here: Session Resource

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while listing objects using boto3: botocore.parsers ...
For your case, the response type is JSON , where boto3 tries to parse it with XML format. You need to request explicitly...
Read more >
S3 create bucket should not do response in json - rgw - Ceph
ResponseParserError : Unable to parse response (not well-formed (invalid token): line 1, column 0), invalid XML received: ...
Read more >
XML parse error: no head element found - WordPress.org
I have installed several plugins and the one i am having issues with now is “Seriously Simple Podcasting” Somehow the rss feed is...
Read more >
Unable to parse - Common causes and quick fixes - Opster
A detailed guide on how to resolve errors related to "unable to parse"
Read more >
localstack/Platform - Gitter
Unable to parse response (not well-formed (invalid token): line 1, column 0), invalid XML received. Further retries may succeed:\nb'{}'. recharge-dreams.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found