Python: Querying FoodData Central with Python Requests
I need help with this API request . I keep getting the following error:
{'timestamp': '2019-10-16T04:41:10.248+0000', 'status': 415, 'error': 'Unsupported Media Type', 'message': "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported", 'path': '/portal-data/api/v1/search'}
print("Food Menu") API_KEY = 'gR9vZKeNzfQBaNMLClCtYoPPM6RRY9BPZyz4hO7D ' target_url = "https://api.nal.usda.gov/fdc/v1/search" params = {'generalSearchInput':'almond'} headers = {"x-api-key":API_KEY} response = requests.post(target_url, headers=headers, data=params).json() print(response)
Use this HEADER, You will not get 415 error.
headers={'Content-type':'application/json',
'Accept':'application/json',"x-api-key":API_KEY}
SEE IMAGE
Thanks, PLEASE COMMENT if there is any concern.
Python: Querying FoodData Central with Python Requests I need help with this API request . I...
I want to use BING API for web searching using python. Search result should only contain PDF. I added the advanced operator (filetype: pdf) in the search query. But seems it not working. ******** Python code ************** import requests def bing_search(query): url = 'https://api.cognitive.microsoft.com/bing/v5.0' # query string parameters payload = {'q': query, 'filetype':'pdf','responseFilter':'Webpages'} # custom headers headers = {'Ocp-Apim-Subscription-Key': '9126a2280100424b90b85d764a18dc34'} # make GET request r = requests.get(url, params=payload, headers=headers) # get JSON response return r.json() j = bing_search('Machine Learning') print(j.get('webPages',...
I will like to compare automobile producers. This assignment suppose to read data like div tags a etc. And count occurrence of them. Reading from a URL while working with an API (using Mediawiki API as an example) Input: Will be obtained from a URL using Mediawiki API -- starter code below Output: Up to you... sort of. What to submit: Upload a report (.pdf preferred) containing screenshots of code, output, and discussion/conclusions to d2l dropbox. Please also submit your...
This is a python question. Start with this program, import json from urllib import request def main(): to_continue = 'Yes' while to_continue == 'yes' or to_continue == 'Yes': currency_code = input("Enter currency code: ").upper() dollars = int(input("Enter number of dollar you want to convert: ")) # calling the exchange_rates function data = get_exchange_rates() if currency_code in data["rates"].keys(): currency = data["rates"][currency_code] # printing the the currency value by multiplying the dollars amount. print("The value is:", str(currency * dollars)) else: print("Error: the...