Python Microframework Bottle无法正常工作

时间:2017-08-17 17:59:20

标签: python opencv request bottle

from bottle import route, run, get, request, static_file
import numpy as np
import pytesseract
from skimage.color import rgb2gray
from skimage import data
from skimage import io
from PIL import Image

def imageProcessing(image):
    img = io.imread(image)
    img = rgb2gray(img)
    io.imsave('sr.png', img)
    im = Image.open(static_file('sr.png', root='sr.png'))
    bg = Image.new("L", im.size, "white")
    print "made bg"
    bg.paste(im)
    txt = pytesseract.image_to_string(bg)
    return txt

@get('/a')
def test():
    url = request.get('url')
    if url:
        text = imageProcessing(url)       
        return {"url": url, "txt": text, "entities": arrayOfEntities}
    else:
        return {"url": url}

run(host='localhost', port=8080, reloader=True)

任何人都可以向我解释为什么这不起作用?我认为代码没有任何关系,我已经花了几个小时研究这个问题。我可能错了。

为什么它总是返回“url”:null?如何让它注册URL?

非常感谢。

1 个答案:

答案 0 :(得分:0)

您必须使用request.GET

@get('/a')
def test():
    url = request.GET.get('url')
    if url:
        text = imageProcessing(url)       
        return {"url": url, "txt": text, "entities": arrayOfEntities}
    else:
        return {"url": url}