【发布时间】:2016-06-15 06:58:43
【问题描述】:
我正在尝试使用 Fitbit API 下载我的数据。我已经想出了如何获取某一天的数据,这很好。这是我使用的 curl 命令:
curl -i -H "Authorization: Bearer (here goes a very long token)" https://api.fitbit.com/1/user/-/activities/heart/date/2016-6-14/1d/1sec/time/00:00/23:59.json >> heart_rate_20160614.json
但是,我想收集数百天的数据,我不想手动进行。所以我想我可以使用 Python 循环。我阅读了一些其他主题,例如this one 和this one,但仍然不知道如何使用 urllib2 将这些 curl 命令“翻译”成 python 语言。
我试过这个:
import urllib2
url = 'https://api.fitbit.com/1/user/-/activities/heart/date/today/1d/1sec/time/00:00/00:01.json'
data = '{Authorization: Bearer (here goes a very long token)}'
req = urllib2.Request(url,data)
f = urllib2.urlopen(req)
但出现错误提示“HTTP Error 404: Not Found”
那么将这个 curl 命令“翻译”成 python 语言的正确方法是什么?谢谢!
【问题讨论】:
标签: python curl request urllib2