我正在尝试使用bitfinex rest api获取一些数据,但参数不适用,而且我得到的数据不正确。有人能告诉我什么错吗?
import requests
import json
URL = 'https://api.bitfinex.com/v2/trades/tBTCUSD/hist'
params = {
'start': 1482400030, # I expect to get piece of data starting from this timestamp
'limit': 1000,
}
response = requests.get(URL, params=json.dumps(params))
谢谢!
答案 0 :(得分:0)
是什么目的params=json.dumps(params)
?
response = requests.get(URL, params=params)
工作正常
json.dumps
插入不必要的双引号
检查下面的区别:
>>> json.dumps(params)
'{"start": 1482400030, "limit": 1000}'
>>> response = requests.get(URL, params=json.dumps(params))
>>> response.url
u'https://api.bitfinex.com/v2/trades/tBTCUSD/hist?%7B%22start%22:%201482400030,%20%22limit%22:%201000%7D'
>>> response = requests.get(URL, params=params)
>>> response.url
u'https://api.bitfinex.com/v2/trades/tBTCUSD/hist?start=1482400030&limit=1000'