"SyntaxError:关键字arg之后的非关键字arg"使用requests.post()时Python中的错误

Oli*_*ett 7 python post arguments

response = requests.post("http://api.bf3stats.com/pc/player/", data = player, opt)
Run Code Online (Sandbox Code Playgroud)

在python IDLE中运行此行以测试我遇到的语法错误:关键字arg之后的非关键字arg.

不知道什么事发生在这里.

player并且opt是包含一个单词字符串的变量.

Joh*_*die 17

尝试:

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

您不能在关键字参数后面放置非关键字参数.

有关详细信息,请查看http://docs.python.org/2.7/tutorial/controlflow.html?highlight=keyword%20args#keyword-arguments上的文档.


Mos*_*faR 5

它应该是这样的:

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

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