2017-08-17 101 views
0
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) 

任何人都可以向我解釋爲什麼這不起作用?我認爲代碼中沒有任何東西,我一直在爲此工作數小時。但我可能是錯的。Python Microframework Bottle not working

爲什麼總是返回「url」:null?我怎樣才能使它註冊的URL?

非常感謝。

+0

你怎麼罵你的網頁? 'HTTP://本地主機:8080 /一個url = xyz'? – Daniel

+0

@Daniel是的,這就是我所做的 – SR1

回答

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}