为什么 curl 会截断这个查询字符串? [英] Why is curl truncating this query string?

查看:33
本文介绍了为什么 curl 会截断这个查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定,这个问题的答案将是一些非常明显的字符编码问题...

I'm sure the answer to this is going to be some painfully obvious character encoding issue...

我在命令行上使用 curl 来测试 python 应用程序中的一些端点.端点采用纬度和经度的 url 参数.没什么特别的.我输入了命令:

I'm using curl on the command line to test some endpoints in a python app. The endpoint takes url params of latitude and longitude. Nothing too special. I put in the command:

curl -v -L http://localhost:5000/pulse/?lat=41.225&lon=-73.1

服务器响应,带有详细的 curl 输出:

Server responds, with verbose curl output:

* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET /pulse/?lat=41.225 HTTP/1.1
> User-Agent: curl/7.21.6 (i686-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
> Host: localhost:5000
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 500 INTERNAL SERVER ERROR
< Content-Type: application/json
< Content-Length: 444
< Server: Werkzeug/0.8.1 Python/2.7.2+
< Date: Wed, 01 Feb 2012 17:06:29 GMT
< 
{
    "msg": "TypeError: float() argument must be a string or a number", 
    "flag": 0, 
    "stack": [
        "Traceback (most recent call last):", 
        "  File "engine.py", line 139, in dispatch_request", 
        "    return getattr(self, 'action_'+endpoint)(request, **values)", 
        "  File "engine.py", line 818, in action_getpulse", 
        "    lon = float(request.args.get('lon'))"
    ], 
    "err": 1
* Closing connection #0
}
[1]+  Done

在该转储的第二行,很明显第二个参数 lon 没有被发送.我究竟做错了什么?谢谢.

On the second line of that dump, it's obvious that the second param, lon, isn't being sent. What am I doing wrong? Thanks.

推荐答案

问题的答案,我做错了什么",是 shell 看到 & 符号 (&) 并认为这是命令的结尾(并将其放入后台).您需要引用它,这就是引用字符串的答案有效的原因.你可以很容易地运行这个:

The answer to the question, "what am I doing wrong," is that the shell sees the ampersand (&) and thinks that's the end of the command (and puts it into the background). You need to quote it, which is why the answers that quoted the string work. You could just as easily run this:

curl -v -L "http://localhost:5000/pulse?lat=41.225&lon=-73.1"

这篇关于为什么 curl 会截断这个查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆