Google 应用引擎给我 400 错误请求状态代码?

发布于 2024-12-22 00:48:48 字数 565 浏览 2 评论 0原文

在谷歌应用程序引擎中:

urlfetch.fetch('http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|Tested: 21 Dec') works fine.

但是当我这样做时:

text = 'Tested: 21 Dec'  // This ia a variable
my_url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|'+text
urlfetch.fetch(my_url)

现在这给出了400错误。我意识到这不能识别 | 之后的字符。因此,这只会调用 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|

有什么建议吗?

In google appengine:

urlfetch.fetch('http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|Tested: 21 Dec') works fine.

But when i do this way:

text = 'Tested: 21 Dec'  // This ia a variable
my_url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|'+text
urlfetch.fetch(my_url)

Now this gives 400 error. What I realize that this is not recognizing characters after | . So, this makes call to only 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|

Any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日暮斜阳 2024-12-29 00:48:48

不确定这是否是问题所在,但您应该在使用字符串构建 url 之前对其进行编码:

import urllib
text = urllib.quote_plus('Tested: 21 Dec')  // This ia a variable
my_url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|%s' % text
urlfetch.fetch(my_url)

此外,在大多数情况下,最好使用字符串格式 '... %s' % (a,b) 或 ''.join([a, b]) 而不是 a + b

Not sure if this is the problem, but you should encode your strings before constructing url with them:

import urllib
text = urllib.quote_plus('Tested: 21 Dec')  // This ia a variable
my_url = 'http://chart.apis.google.com/chart?chst=d_text_outline&chld=000000|12|h|FFFFFF|_|%s' % text
urlfetch.fetch(my_url)

Also in most cases it is better practice to use string formatting '... %s' % (a,b) or ''.join([a, b]) instead of a + b.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文