# Buggy code
def replay_command(command):
    function = getattr(requests, command["m"].lower())
    data = command["d"]
    if data:
        data = base64.b64decode(data)
    endpoint = aws_stack.get_local_service_url(command["a"])
    full_url = (endpoint[:-1] if endpoint.endswith("/") else endpoint) + command["p"]
    result = function(full_url, data=data, headers=command["h"])
    return result


# Traceback (SSLError)
localstack_1      | 2018-03-06 09:33:15,386 INFO spawned: 'infra' with pid 7848
localstack_1      | (. .venv/bin/activate; exec bin/localstack start)
localstack_1      | Starting local dev environment. CTRL-C to quit.
localstack_1      | Starting mock DynamoDB (https port 12000)...
localstack_1      | Starting mock S3 (https port 443)...
localstack_1      | Starting mock DynamoDB Streams service (https port 4570)...
localstack_1      | Initializing DynamoDB Local with the following configuration:
localstack_1      | Port:       4564
localstack_1      | InMemory:   false
localstack_1      | DbPath:     /tmp/localstack/data/dynamodb
localstack_1      | SharedDb:   true
localstack_1      | shouldDelayTransientStatuses:       false
localstack_1      | CorsParams: *
localstack_1      |
localstack_1      | 2018-03-06 09:33:17,346 INFO success: infra entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
localstack_1      | * Running on http://0.0.0.0:4563/ (Press CTRL+C to quit)
localstack_1      | 127.0.0.1 - - [06/Mar/2018 09:33:19] "GET / HTTP/1.1" 200 -
localstack_1      | Error starting infrastructure: HTTPSConnectionPool(host='afcc8dd10072', port=443): Max retries exceeded with url: /test (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', '$sl3_get_server_certificate', 'certificate verify failed')],)",),)) Traceback (most recent call last):
localstack_1      |   File "/opt/code/localstack/localstack/services/infra.py", line 484, in start_infra
localstack_1      |     restore_persisted_data(apis=apis)
localstack_1      |   File "/opt/code/localstack/localstack/services/infra.py", line 219, in restore_persisted_data
localstack_1      |     persistence.restore_persisted_data(api)
localstack_1      |   File "/opt/code/localstack/localstack/utils/persistence.py", line 92, in restore_persisted_data
localstack_1      |     return replay(api)
localstack_1      |   File "/opt/code/localstack/localstack/utils/persistence.py", line 84, in replay
localstack_1      |     replay_command(command)
localstack_1      |   File "/opt/code/localstack/localstack/utils/persistence.py", line 68, in replay_command
localstack_1      |     result = function(full_url, data=data, headers=command['h'])
localstack_1      |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/requests/api.py", line 126, in put
localstack_1      |     return request('put', url, data=data, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/requests/api.py", line 58, in request
localstack_1      |     return session.request(method=method, url=url, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
localstack_1      |     resp = self.send(prep, **send_kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
localstack_1      |     r = adapter.send(request, **kwargs)
localstack_1      |   File "/opt/code/localstack/.venv/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
localstack_1      |     raise SSLError(e, request=request)
localstack_1      | SSLError: HTTPSConnectionPool(host='afcc8dd10072', port=443): Max retries exceeded with url: /test (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certi$icate', 'certificate verify failed')],)",),))
localstack_1      |
localstack_1      | 2018-03-06 09:33:19,925 INFO reaped unknown pid 7877
localstack_1      | 2018-03-06 09:33:19,927 INFO reaped unknown pid 7886
localstack_1      | ERROR: HTTPSConnectionPool(host='afcc8dd10072', port=443): Max retries exceeded with url: /test (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certifica
te', 'certificate verify failed')],)",),))
localstack_1      | 2018-03-06 09:33:21,953 INFO reaped unknown pid 7884
localstack_1      | 2018-03-06 09:33:21,956 INFO exited: infra (exit status 0; expected)

# Fixed code
def replay_command(command):
    function = getattr(requests, command["m"].lower())
    data = command["d"]
    if data:
        data = base64.b64decode(data)
    endpoint = aws_stack.get_local_service_url(command["a"])
    full_url = (endpoint[:-1] if endpoint.endswith("/") else endpoint) + command["p"]
    result = function(full_url, data=data, headers=command["h"], verify=False)
    return result