bigchaindb / bigchaindb-driver

Official Python driver for BigchainDB
https://www.bigchaindb.com
Apache License 2.0
104 stars 104 forks source link

Curl success, but Internal Server Error when commit transaction #501

Open leejie8008 opened 5 years ago

leejie8008 commented 5 years ago

Description

I set up bigchaindb, with python driver and mongodb. Then, I try to run the code from Basic Usage Example, and receive Internal Server Error, but when I run curl http://localhost:9984/api/v1/transactions, it shows {"message": {"asset_id": "Missing required parameter in the JSON body or the post body or the query string"}}, which means that my connection is established.

How can I debug form here?

What I Did

from bigchaindb_driver import BigchainDB
from bigchaindb_driver.crypto import generate_keypair
from time import sleep
from sys import exit

bdb_root_url = 'localhost:9984'
# bdb_root_url = 'http://127.0.0.1:9984'
bdb = BigchainDB(bdb_root_url)

bicycle_asset = {
    'data': {
        'bicycle': {
            'serial_number': 'abcd1234',
            'manufacturer': 'bkfab'
        },
    },
}

bicycle_asset_metadata = {
    'planet': 'earth'
}

alice, bob = generate_keypair(), generate_keypair()

prepared_creation_tx = bdb.transactions.prepare(
    operation='CREATE',
    signers=alice.public_key,
    asset=bicycle_asset,
    metadata=bicycle_asset_metadata
)

fulfilled_creation_tx = bdb.transactions.fulfill(
    prepared_creation_tx,
    private_keys=alice.private_key
)

sent_creation_tx = bdb.transactions.send_commit(fulfilled_creation_tx)

txid = fulfilled_creation_tx['id']

print("tid: " + txid)

asset_id = txid

transfer_asset = {
    'id': asset_id
}

output_index = 0
output = fulfilled_creation_tx['outputs'][output_index]

transfer_input = {
    'fulfillment': output['condition']['details'],
    'fulfills': {
        'output_index': output_index,
        'transaction_id': fulfilled_creation_tx['id']
    },
    'owners_before': output['public_keys']
}

prepared_transfer_tx = bdb.transactions.prepare(
    operation='TRANSFER',
    asset=transfer_asset,
    inputs=transfer_input,
    recipients=bob.public_key,
)

fulfilled_transfer_tx = bdb.transactions.fulfill(
    prepared_transfer_tx,
    private_keys=alice.private_key,
)

sent_transfer_tx = bdb.transactions.send_commit(fulfilled_transfer_tx)

print("Is Bob the owner?",
    sent_transfer_tx['outputs'][0]['public_keys'][0] == bob.public_key)

print("Was Alice the previous owner?",
    fulfilled_transfer_tx['inputs'][0]['owners_before'][0] == alice.public_key)

My stacktrace

vagrant@ubuntu-bionic:/vagrant$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 79, in <module>
    sent_creation_tx = bdb.transactions.send_commit(fulfilled_creation_tx)
  File "/usr/local/lib/python3.6/dist-packages/bigchaindb_driver/driver.py", line 375, in send_commit
    headers=headers)
  File "/usr/local/lib/python3.6/dist-packages/bigchaindb_driver/transport.py", line 82, in forward_request
    backoff_cap=backoff_cap,
  File "/usr/local/lib/python3.6/dist-packages/bigchaindb_driver/connection.py", line 91, in request
    **kwargs,
  File "/usr/local/lib/python3.6/dist-packages/bigchaindb_driver/connection.py", line 128, in _request
    raise exc_cls(response.status_code, text, json, kwargs['url'])
bigchaindb_driver.exceptions.TransportError: (500, '{"message": "Internal Server Error"}\n', {'message': 'Internal Server Error'}, 'http://localhost:9984/api/v1/transactions/')

vagrant@ubuntu-bionic:/vagrant$ curl http://localhost:9984
{"api":{"v1":{"assets":"/api/v1/assets/","blocks":"/api/v1/blocks/","docs":"https://docs.bigchaindb.com/projects/server/en/v2.0.0b9/http-client-server-api.html","metadata":"/api/v1/metadata/","outputs":"/api/v1/outputs/","streams":"ws://localhost:9985/api/v1/streams/valid_transactions","transactions":"/api/v1/transactions/","validators":"/api/v1/validators"}},"docs":"https://docs.bigchaindb.com/projects/server/en/v2.0.0b9/","software":"BigchainDB","version":"2.0.0b9"}

vagrant@ubuntu-bionic:/vagrant$ curl http://localhost:9984/api/v1/transactions
{"message": {"asset_id": "Missing required parameter in the JSON body or the post body or the query string"}}
LuffySmile commented 4 years ago

I have the same problem. Have you solved it now?

xiaowei6688 commented 2 years ago

@LuffySmile Have you solved it

Yehezkiel-simbuang commented 1 year ago

@LuffySmile @xiaowei6688 Have you solve it? I have same issue here