为什么在Python-Bottle Restful中无法识别完整的URL

时间:2019-10-05 04:08:37

标签: python shell bottle

我正在使用Python上的Bottle对MongoDB进行更新。我正在尝试从网址中获取两个参数,但只能读取其中一个。我检查了网址,但它不完整。我正在发送:

curl http://localhost:8080/update?id="10011-2017-TEST"&result="Violation%20Issued"

但是服务器抛出

GET curl http://localhost:8080/update?id="10011-2017-TEST"
@route('/update', method='GET')
def update_data():
    print("URL"  + request.url)

网址显示:

http://localhost:8080/update?id="10011-2017-TEST" 

这就是为什么我没有第二个参数的原因。我需要以这种方式发送参数:

curl http://localhost:8080/update?id="10011-2017-TEST"&result="Violation%20Issued"

1 个答案:

答案 0 :(得分:0)

这里的问题不是Bottle或您的Web服务器。这就是您在命令行上使用引号的方式。

您需要通过以下方式报价电话:

curl "http://localhost:8080/update?id=10011-2017-TEST&result=Violation%20Issued"

“&”对大多数shell(例如bash)(包括您的shell)都有特殊的含义。 按照您的方式调用它时,外壳程序是interpreting the unquoted ampersand(&),表示“这是命令的结尾,请在后台运行它”。 (实际上,很惊讶您还没有看到类似Unknown command: result=Violation%20Issued的消息)

因此您的curl通话实际上等同于:

curl http://localhost:8080/update?id=10011-2017-TEST

这与您在服务器上看到的一致。

继续阅读how to quote command lines,以了解更多详细信息。