错误提示:can only concatenate str (not "NoneType") to str
我自建一个网站,尝试POST发送数据,但是爬虫端报错。在Flask端显示变量N是空值,明明我在urllib有进行赋值
flask代码:
import flask
app = flask.Flask(name)
@app.route("/",methods = ["POST","GET"])
def index():
try:
province = flask.request.values.get("province")
city = flask.request.values.get("city")
n= flask.request.values.get("n")
print(province,city,n)
return province+"\n"+city+"\n"+n
except Exception as err:
return str(err)
if name =="main":
app.run()
urllib.request代码
import urllib.request
import urllib.parse
province = urllib.parse.quote("广东")
city = urllib.parse.quote("广州")
n = urllib.parse.quote("白云区")
url = "http://127.0.0.1:5000?province="+province+"&city="+city
data = n
print(data)
html = urllib.request.urlopen(url,data=data.encode())
html = html.read()
html = html.decode()
print(html)