我试图通过将"f“参数添加到GET调用中来指定所需的字段(请参阅此处:Patentsview API Python 3.4)。
我认为问题在于我的格式和语法。
我尝试在"q“和"f”参数中添加几种不同的花括号。我返回不同的错误消息。
import requests
title = "computer"
author = "Jobs"
url = "http://www.patentsview.org/api/patents/query"
data = {
"q":{ "_and":[ {"inventor_last_name":author}, {"_text_any":{"patent_title":title}}],
"f":["assignee_lastknown_city","assignee_lastknown_state","assignee_lastknown_country"]},
"o":{"matched_subentities_only":"true"}
}
resp = requests.post(url, json=data)
with open("patents.txt", "w") as f:
f.write(resp.text)这是返回的内容:
{“状态”:“错误”,“有效载荷”:{“错误”:“q‘参数:应该只有一个json对象在顶层字典中。”,“代码”:“RQ3”}
我希望文件具有结果,而不是错误消息。
发布于 2019-07-28 21:59:16
你的剧本中有不平衡的“}”。我纠正了他们。我一直无法测试这些更改是否有效。这是修改后的代码。我认为这是唯一的错误。
import requests
title = "computer"
author = "Jobs"
url = "http://www.patentsview.org/api/patents/query"
data = {"q":{ "_and":[ {"inventor_last_name":author}, {"_text_any":{"patent_title":title}}]},"f":["assignee_lastknown_city","assignee_lastknown_state","assignee_lastknown_country"],"o":{"matched_subentities_only":"true"}}
resp = requests.post(url, json=data)
with open("patents.txt", "w") as f:
f.write(resp.text)如果对你有用,请告诉我。
发布于 2019-07-28 21:58:58
查询数据中有错误。只要做一些修改,它就能工作:
import requests
title = "computer"
author = "Jobs"
url = "http://www.patentsview.org/api/patents/query"
data = {
"q": {
"_and": [
{
"inventor_last_name": author
},
{
"_text_any": {
"patent_title": title
}
}
],
},
"f": [
"assignee_lastknown_city",
"assignee_lastknown_state",
"assignee_lastknown_country"
],
"o": {
"matched_subentities_only": "true"
}
}
resp = requests.post(url, json=data)
with open("patents.txt", "w") as f:
f.write(resp.text)基本上,我把f搬到了q外面
--- op_data.txt 2019-07-28 18:37:07.000000000 -0400
+++ my_data.txt 2019-07-28 18:37:07.000000000 -0400
@@ -9,13 +9,13 @@
"patent_title": "computer"
}
}
- ],
- "f": [
- "assignee_lastknown_city",
- "assignee_lastknown_state",
- "assignee_lastknown_country"
]
},
+ "f": [
+ "assignee_lastknown_city",
+ "assignee_lastknown_state",
+ "assignee_lastknown_country"
+ ],
"o": {
"matched_subentities_only": "true"
}https://stackoverflow.com/questions/57245206
复制相似问题