So I'm trying to learn python so I can work with an api. The tutorial I was using was using python 2 and urllib. I'm running python 3.6, so it wasn't working. So I decided to try and learn about requests. I'm having a little bit of trouble converting from urllib to requests.
import requests import json parameters = {"apikey": "mykey", "queries": "SN74S74N"} response = requests.get("http://octopart.com/api/v3/parts/match", params = parameters) data = response.json() #print(type(data)) print(data) The error I get when I run this is
{'message': 'JSON decode error: SN74S74N', '__class__': 'ClientErrorResponse'} I'm not sure why I'm getting this error. But I think it might be because my parameters aren't set up right. Is requests capable of doing the same thing they have in the documentation? https://octopart.com/api/docs/v3/rest-api#endpoints-parts-match
Sorry this is vague, I just started learning python and apis. Will be around to further clarify any questions.
queries=shouldn't be a simple string likeSN74S74N.queriesvalue isn't in the format they expect. Requests is doing what it should, but you'll need to work on formatting the query.querieslist of dicts, serialize it into json, then pass that in as part of your dict -parameters = {"apikey": "mykey", "queries": json.dumps(queries)}.requestshandles the URI escaping but you still need to give it json.