【问题标题】:"SyntaxError: non-keyword arg after keyword arg" Error in Python when using requests.post()使用 requests.post() 时 Python 中的“语法错误:关键字 arg 后的非关键字 arg”错误
【发布时间】:2013-03-30 20:45:21
【问题描述】:
response = requests.post("http://api.bf3stats.com/pc/player/", data = player, opt)

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

不知道这里发生了什么。

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

【问题讨论】:

    标签: python post arguments


    【解决方案1】:

    试试:

    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 的文档以获取更多信息。

    【讨论】:

      【解决方案2】:

      应该是这样的:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多