- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用 app.mount 时尝试在 URL 路径中使用特殊字符失败:
http://127.0.0.1:8080/test/äöü
结果:
Error: 400 Bad Request
Invalid path string. Expected UTF-8
测试.py:
#!/usr/bin/python
import bottle
import testapp
bottle.debug(True)
app = bottle.Bottle()
app.mount('/test',testapp.app)
app.run(reloader=True, host='0.0.0.0', port=8080)
run(host="localhost",port=8080)
测试应用程序.py:
import bottle
app = bottle.Bottle()
@app.route("/:category", method=["GET","POST"])
def admin(category):
try:
return category
except Exception(e):
print ("e:"+str(e))
当不使用 app.mount 时相同的代码运行良好:
测试工作.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bottle
import testapp
bottle.debug(True)
app = bottle.Bottle()
@app.route("/test/:category", method=["GET","POST"])
def admin(category):
try:
return category
except Exception(e):
print ("e:"+str(e))
app.run(reloader=True, host='0.0.0.0', port=8080)
run(host="localhost",port=8080)
这看起来像是一个错误,还是我在这里遗漏了什么? :/
最佳答案
是的,这似乎是瓶中的一个错误。
问题出在_handle
方法:
def _handle(self, environ):
path = environ['bottle.raw_path'] = environ['PATH_INFO']
if py3k:
try:
environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
except UnicodeError:
return HTTPError(400, 'Invalid path string. Expected UTF-8')
这里environ['PATH_INFO']
被转成了utf8,所以当挂载的app再次调用同样的方法时,内容已经是utf8,所以转会失败。
一个非常快速的解决方法是更改该代码以跳过已经完成的转换:
def _handle(self, environ):
converted = 'bottle.raw_path' in environ
path = environ['bottle.raw_path'] = environ['PATH_INFO']
if py3k and not converted:
try:
environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
except UnicodeError:
return HTTPError(400, 'Invalid path string. Expected UTF-8')
提交一份针对 bottle 的错误报告可能会很好。
关于 python 瓶 : UTF8 path string invalid when using app. mount(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168292/
我收到以下错误: (virtualenv)[chirdeep@fedora-desktop ~]$ python programs/python/myrestapi.py Traceback (mos
我有一个问题。我安装了 pgadmin3。创建了一个编码为 UTF-8 的库。创建一个文件index.py: # -*- coding utf-8 -*- from bottle import rou
好吧,所以这可能有点不正统或者我只是愚蠢或两者兼而有之:) 我正在尝试一个非常简单的设置,我在一个 Process 实例中启动一个 bottle 服务器,并在另一个实例中启动一个小型 TFTP 服务器
当我尝试运行此示例中的服务器时,我可以看到它在正确的端口上运行。但是,无法从外部访问它(内部服务器错误),也无法通过常见方法在控制台中对其进行调试(看不到任何输出)。 我确定端口可用并且服务器正在运行
我想为 Sierra 创建一瓶 zsh 5.1.1,因为 zsh 5.2 有一个非常糟糕的错误,它破坏了某些功能。 Sierra 附带 zsh 5.2,它在多字节绑定(bind)键击中被破坏(参见:h
当 http GET 请求发送到特定路由时,我尝试调用函数,但我想将参数传递给给定函数。例如,我有以下内容: self.app.route('/here', ['GET'], self.her
我开始开发一个 Python 3.4 应用程序,用 Bottle 框架为一个小网站(主要是媒体库)提供服务。我正在使用 Bottle 的“简单模板引擎” 我有一个 YAML 文件,指向一个包含图像和其
自从 versions 被删除以来,我一直无法找到安装以前版本软件的方法。命令并点击 Homebrew。我在 2008 Mac Pro (3,1) 上运行 macOS 10.14.3 (Mojave)
我正在使用Bottle用于渲染网页的 Web 框架。我使用 Bottle 模板引擎从 Python 传递变量,然后在嵌入了 Python 代码的模板文件中对它们进行相应的处理。 现在,当我在模板中使用
@route('/locations', method='GET') def get_location(): entity = db['locations'].find({'coordinat
在使用 app.mount 时尝试在 URL 路径中使用特殊字符失败: http://127.0.0.1:8080/test/äöü 结果: Error: 400 Bad Request Invali
我最近收到了一个部分完成的项目,而且我对使用 Bottle 还不熟悉。我遇到过这样的情况:我在 AJAX 请求中发送字典,而 Bottle 位于服务器端。字典看起来像这样(在 JavaScript 中
我的服务器处理多个网站,其中大多数使用 Apache、PHP 等。 但其中一个 (www.mywebsite.com) 使用 Python Web 服务器,该服务器监听端口 8092。因此,此 Apa
我是一名优秀的程序员,十分优秀!