Python 3.x Coinbase Pro post请求-格式错误的JSON

Python 3.x Coinbase Pro post请求-格式错误的JSON,python-3.x,python-requests,coinbase-api,gdax-api,Python 3.x,Python Requests,Coinbase Api,Gdax Api,我目前正在开发一款软件,可以自动与Coinbase Pro进行交易。我使用的是请求库,代码适用于“GET”请求,但无法用于“POST”。我想知道是否有人能帮我了解发生了什么事 这是我当前使用的代码: import time import hmac import hashlib import base64 import requests from requests.auth import AuthBase class CoinbaseExchangeAuth(AuthBase): def _

我目前正在开发一款软件,可以自动与Coinbase Pro进行交易。我使用的是请求库,代码适用于“GET”请求,但无法用于“POST”。我想知道是否有人能帮我了解发生了什么事

这是我当前使用的代码:

import time
import hmac
import hashlib
import base64
import requests
from requests.auth import AuthBase

class CoinbaseExchangeAuth(AuthBase):
  def __init__(self, api_key, secret_key, passphrase):
    self.api_key = api_key
    self.secret_key = secret_key
    self.passphrase = passphrase

  def __call__(self, request):
    timestamp = str(time.time())
    message = timestamp + request.method + request.path_url + (request.body or '')
    message = message.encode('utf-8')
    hmac_key = base64.b64decode(self.secret_key)
    signature = hmac.new(hmac_key, message, hashlib.sha256)
    signature_b64 = base64.b64encode(signature.digest())

    request.headers.update({
        'CB-ACCESS-SIGN': signature_b64,
        'CB-ACCESS-TIMESTAMP': timestamp,
        'CB-ACCESS-KEY': self.api_key,
        'CB-ACCESS-PASSPHRASE': self.passphrase,
        'Content-Type': 'application/json'
    })
    return request
与以下各项一起使用时:

api_url = "https://api.pro.coinbase.com/"
auth = CoinbaseExchangeAuth("*****", "*****", "*****")
request = requests.get(api_url + "accounts", auth=auth).json()
它工作得很好。但一旦我尝试:

order = {'size': '0.0001', 'price': '100', 'side': 'sell', 'product_id': 'BTC-EUR'}
request = requests.post(api_url + "orders", data=order, auth=auth)
print(request.json())
我得到了
{'message':'malformed json'}
。我想这和
(request.body或“”)
有关,但我找不到解决方法


谢谢任何人的帮助

最后,问题是
request=requests.post(api_url+“orders”,data=order,auth=auth)
-
request=requests.post(api_url+“orders”,data=json.dumps(order),auth=auth)
解决了这个问题