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

问题描述 投票:0回答:1

我正在使用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)

URL显示:

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

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

curl http://localhost:8080/update?id="10011-2017-TEST"&result="Violation%20Issued"
python shell bottle
1个回答
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了解更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.