API请求参数被忽略
该代码按预期工作,并显示了3个最近的Wikipedia编辑。
我的问题是,如果我删除第二个URL线,则如果未列出用户,我应该获得三次或无的 urmi27 。 但是我得到两个URL的列表。 API请求忽略了“动作”?
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
#URL = "https://en.wikipedia.org/w/api.php?action=feedcontributions&user=Urmi27"
PARAMS = {
"format": "json",
"rcprop": "comment|loginfo|title|ids|sizes|flags|user",
"list": "recentchanges",
"action": "query",
"rclimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
RECENTCHANGES = DATA['query']['recentchanges']
for rc in RECENTCHANGES:
print (rc['user'])
This code works as expected and shows 3 recent wikipedia editors.
My question is that if I uncomment the second URL line, I should get Urmi27 three times or None if the user is not listed.
But I get the same list for both URL. Is "action" ignored by api request?
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
#URL = "https://en.wikipedia.org/w/api.php?action=feedcontributions&user=Urmi27"
PARAMS = {
"format": "json",
"rcprop": "comment|loginfo|title|ids|sizes|flags|user",
"list": "recentchanges",
"action": "query",
"rclimit": "3"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
RECENTCHANGES = DATA['query']['recentchanges']
for rc in RECENTCHANGES:
print (rc['user'])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
个位置(在URL和
params
dictionary中定义获取参数您是在2 代码> feedContributions 操作使用不同的参数和不同的返回格式大不相同。
要使用
feedContributions
操作,您需要这样的东西:You are defining GET parameter in 2 places (in the URL and in the
PARAMS
dictionary) and the API is prioritizing thePARAMS
The
query
andfeedcontributions
actions are very different, using different parameters and different return formats.To use the
feedcontributions
action, you would need something like this:API REF