使用浆糊s运行时,瓶子获取请求被某些字符串破坏

2024-05-16 03:53:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个类似的问题: Python bottle: UTF8 path string invalid when using app.mount()

当我试图得到/languages/Inglês时,我收到了下面的错误(注意重音“è”)。当传递[az]字符串时,它工作得很好。在

Critical error while processing request: /languages/Inglês

我尝试了上述链接中提到的修复,但没有成功。在

工作示例

from bottle import route, run, debug

@route('/languages/<name>')
def hello(name):
    return name

if __name__ == '__main__':
    debug(False)
    #run(reloader=False, port = 8080) # works
    run(server='paste', port = 8080)  # fails

使用server='paste'运行会导致崩溃,但使用瓶子服务器运行正常。问题似乎发生在bottle._handle()方法中,其中抛出了UnicodeErrorbottle.py第844行):

^{pr2}$

我在Windows10机器上使用Python 3.6.2Bottle v0.12.13和{}。发生什么事?这是瓶子还是浆糊的问题?在

注意:我已经通过重构所有代码来解决我的问题,使用整数id而不是名称。但我还是想了解更多。在

堆栈跟踪:

Critical error while processing request: /hello/inglês

Error:

RuntimeError('Request context not initialized.',)
Traceback:

Traceback (most recent call last):
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 1661, in fget
    try: return ls.var
AttributeError: '_thread._local' object has no attribute 'var'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 954, in wsgi
    out = self._cast(self._handle(environ))
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 907, in _cast
    out = self.error_handler.get(out.status_code, self.default_error_handler)(out)
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 842, in default_error_handler
    return tob(template(ERROR_PAGE_TEMPLATE, e=res))
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 3619, in template
    return TEMPLATES[tplid].render(kwargs)
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 3409, in render
    self.execute(stdout, env)
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 3396, in execute
    eval(self.co, env)
  File "<string>", line 17, in <module>
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 1249, in url
    return self.urlparts.geturl()
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 165, in __get__
    key, storage = self.key, getattr(obj, self.attr)
  File "C:\Users\fernando.filho\AppData\Local\Programs\Python\Python36\lib\site-packages\bottle.py", line 1663, in fget
    raise RuntimeError("Request context not initialized.")
RuntimeError: Request context not initialized.

Tags: inpybottlelibpackageslocallinesite