使用USDA API

时间:2019-02-12 23:11:36

标签: python api

USDA API参考链接:https://ndb.nal.usda.gov/ndb/doc/apilist/API-SEARCH.md

我当前正在用Python创建一个引用USDA Search API的程序。我试图通过将&ds = SR添加到API链接(例如下面的链接)中来将数据源参数设置为“标准参考”,但是此操作不起作用。

  

https://api.nal.usda.gov/ndb/search/?format=json&q=butter&sort=n&max=25&offset=0&api_key=DEMO_KEY&ds=SR

我在做什么错?如何获得API链接以在结果中同时显示不同食物的食物组?

谢谢!

1 个答案:

答案 0 :(得分:1)

您遇到此错误:

  File "/private/var/folders/js/c2_gdy711m7933z9bxcv2q5h0000gn/T/pip-install-jv2fugnm/GDAL/setup.py", line 154, in fetch_config
    raise gdal_config_error(e)
__main__.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/js/c2_gdy711m7933z9bxcv2q5h0000gn/T/pip-install-jv2fugnm/GDAL/

它暗示{ "errors": { "error": [ { "status": 400, "parameter": "ds", "message": "Unknown ds (Data Source) -- can be Branded Food Products or Standard Reference." } ] } } 参数应该是dsBranded Food Products,因此请使用https://api.nal.usda.gov/ndb/search/?format=json&q=butter&sort=n&max=25&offset=0&api_key=DEMO_KEY&ds=Standard%20Reference ...voilà!

Standard Reference