使用 requests.post() 时 Python 中的“SyntaxError: non-keyword arg after keyword arg”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15723294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:47:34  来源:igfitidea点击:

"SyntaxError: non-keyword arg after keyword arg" Error in Python when using requests.post()

pythonpostarguments

提问by Oliver Bennett

response = requests.post("http://api.bf3stats.com/pc/player/", data = player, opt)

After running this line in the python IDLE to test things i encounter the syntax error: non-keyword arg after keyword arg.

在 python IDLE 中运行这一行来测试之后,我遇到了语法错误:关键字 arg 之后的非关键字 arg。

Don't know whats going here.

不知道这里是什么情况。

playerand optare variables that contain a one word string.

playeropt是包含一个单词字符串的变量。

采纳答案by John Brodie

Try:

尝试:

response = requests.post("http://api.bf3stats.com/pc/player/", opt, data=player)

response = requests.post("http://api.bf3stats.com/pc/player/", opt, data=player)

You cannot put a non-keyword argument after a keyword argument.

您不能在关键字参数之后放置非关键字参数。

Take a look at the docs at http://docs.python.org/2.7/tutorial/controlflow.html?highlight=keyword%20args#keyword-argumentsfor more info.

查看http://docs.python.org/2.7/tutorial/controlflow.html?highlight=keyword%20args#keyword-arguments上的文档了解更多信息。

回答by MostafaR

It should be something like this:

它应该是这样的:

response = requests.post("http://api.bf3stats.com/pc/player/", data=player, options=opt)

Because you can not pass a non-keyword argument (opt) after a keyword argument (data=player).

因为您不能在关键字参数 ( opt) 之后传递非关键字参数 ( data=player)。