Previously my calls to PatentsView were working. Specifically, I recall running the below code block (from another stackoverflow post) and getting a non-error output. Now I'm getting a 400 error. What might have changed to cause this? Perhaps the requests library? I get a result by pasting the following result in a browser, but cannot replicate with the requests library (even when I reduce the query params to simplify the call). Params f and o are not required, and the "_and" criteria is also not required. You can simply pass q={"_gte":{"patent_date":"2007-01-04"}} after the url and question mark to get a valid result. This is very odd.
from urllib.request import Request, urlopen
import json
url = "http://www.patentsview.org/api/patents/query"
author = "Jobs"
title = "computer"
data = {
'q':{
"_and":[
{"inventor_last_name":author},
{"_text_any":{"patent_title":title}}
]
},
'o':{"matched_subentities_only": "true"}
}
resp = urlopen(Request(url, json.dumps(data).encode()))
data = resp.read()
#data = json.loads(data)
This seems to be working: