[英]Python Microframework Bottle not working
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)
Can anyone explain to me why this isn't working? 谁能向我解释为什么这行不通? I don't think there is anything off with the code, I've been working on this for hours. 我认为代码没有什么问题,我已经花了好几个小时研究了。 I could be wrong though. 我可能是错的。
Why does it always return "url": null? 为什么总是返回“ url”:null? How can I make it register the URL? 如何注册网址?
Thanks very much. 非常感谢。
You have to use request.GET
: 您必须使用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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.