# Buggy code
def render_PUT(self, request):
    """
    .. http:put:: /wallets/(string:wallet identifier)

    A request to this endpoint will create a new wallet.

        **Example request**:

        .. sourcecode:: none

            curl -X PUT http://localhost:8085/wallets/BTC --data "password=secret"

        **Example response**:

        .. sourcecode:: javascript

            {
                "created": True
            }
    """
    if self.session.lm.market_community.wallets[self.identifier].created:
        request.setResponseCode(http.BAD_REQUEST)
        return json.dumps({"error": "this wallet already exists"})

    def on_wallet_created(_):
        request.write(json.dumps({"created": True}))
        request.finish()

    parameters = http.parse_qs(request.content.read(), 1)

    if self.identifier == "BTC" and "password" not in parameters:
        request.setResponseCode(http.BAD_REQUEST)
        return json.dumps(
            {"error": "a password is required when creating a Bitcoin wallet"}
        )

    if self.identifier == "BTC":  # get the password
        if parameters["password"] and len(parameters["password"]) > 0:
            password = parameters["password"][0]
            self.session.lm.market_community.wallets[self.identifier].create_wallet(
                password=password
            ).addCallback(on_wallet_created)
    else:
        self.session.lm.market_community.wallets[
            self.identifier
        ].create_wallet().addCallback(on_wallet_created)

    return NOT_DONE_YET


# Traceback (EOFError)
Gkr-Message: secret service operation failed: The name org.freedesktop.secrets was not provided by any .service files
Exception in thread tribler-pipe-read:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/bram/git/tribler/TriblerGUI/core_manager.py", line 173, in <lambda>
pipe_thread = Thread(target=lambda: self.pipe_wait(parent_conn), name="tribler-pipe-read")
File "/home/bram/git/tribler/TriblerGUI/core_manager.py", line 158, in pipe_wait
cmd, arg = child_conn.recv()
EOFError

# Fixed code
def render_PUT(self, request):
    """
    .. http:put:: /wallets/(string:wallet identifier)

    A request to this endpoint will create a new wallet.

        **Example request**:

        .. sourcecode:: none

            curl -X PUT http://localhost:8085/wallets/BTC --data "password=secret"

        **Example response**:

        .. sourcecode:: javascript

            {
                "created": True
            }
    """
    if self.session.lm.market_community.wallets[self.identifier].created:
        request.setResponseCode(http.BAD_REQUEST)
        return json.dumps({"error": "this wallet already exists"})

    def on_wallet_created(_):
        request.write(json.dumps({"created": True}))
        request.finish()

    parameters = http.parse_qs(request.content.read(), 1)

    if (
        self.identifier == "BTC" or self.identifier == "TBTC"
    ) and "password" not in parameters:
        request.setResponseCode(http.BAD_REQUEST)
        return json.dumps(
            {"error": "a password is required when creating a Bitcoin wallet"}
        )

    if self.identifier == "BTC" or self.identifier == "TBTC":  # get the password
        if parameters["password"] and len(parameters["password"]) > 0:
            password = parameters["password"][0]
            self.session.lm.market_community.wallets[self.identifier].create_wallet(
                password=password
            ).addCallback(on_wallet_created)
    else:
        self.session.lm.market_community.wallets[
            self.identifier
        ].create_wallet().addCallback(on_wallet_created)

    return NOT_DONE_YET