当参数为空时 Flask return 做什么

What does Flask return when parameters are empty

我正在为道德黑客创建一个网站,他们可以在其中搜索收集 1-5 数据泄露的数据库。我正在让这个应用程序使用 URL 参数,为了使应用程序简单,我只保留参数 我没有使用空白 ex。 username=&password=pass 但我的问题是有时(因为它在此之前工作)returns 一个我无法弄清楚的随机值。

例如,假设变量名为 var1,我做了一个 If 语句——确保它不为空,所以我做

if var1 != "":
    pass

但是有一些奇怪的值正在通过,if 语句仍然是 运行。

我试过的:

我试过向 if 语句添加多个值,这些值也可以是空白的,例如, var1 != "" or var1 != None or var1 != " "

这正是我与 postman 一起使用的 URL,它会抛出一个 500 500 INTERNAL SERVER ERROR

http://localhost:6969/search/shordan?ip=&port=&domain=&formated_domain=&asn=&isp=&orginization=&tag=&product=&city=i&country=u&email=&tel=

注意我只在第一个 if 循环中添加了额外的 or != 语句进行测试,但它不起作用

这些是我的 if 语句

if ip != "" or ip != None or ip != " ":
    IP = f"ip LIKE '%{ip}%' "
    andCounter += 1
    hasIP = True
else:
    IP = ""
if port != "" or port != None:
    Port = f"Port LIKE '%{port}%' "
    andCounter += 1
    hasPort = True
else:
    Port = ""
if domain != "" or domain != None:
    Domain = f"Domain LIKE '%{domain}%' "
    andCounter += 1
    hasDomain = True
else:
    Domain = ""
if formatedDomain != "" or formatedDomain != None:
    FormatedDomain = f"'FORMATED DOMAIN' LIKE '%{formatedDomain}%' "
    andCounter += 1
    hasFormatedDomain = True
else:
    formatedDomain = ""
if asn != "" or asn != None:
    print("asn: " + asn)
    Asn = f"asn LIKE '%{asn}%' "
    andCounter += 1
    hasAsn = True
else:
    Asn = ""
if isp != "" or isp != None:
    ISP = f"ISP LIKE '%{isp}%' "
    andCounter += 1
    hasISP = True
else:
    ISP = ""
if orginization != "" or orginization != None:
    Orginization = f"ORGANIZATION LIKE '%{orginization}%' "
    andCounter += 1
    hasOrginization = True
else:
    Orginization = ""
if tag != "" or tag != None:
    Tag = f"tags LIKE '%{tag}%' "
    andCounter += 1
    hasTag = True
else:
    Tag = ""
if product != "" or product != None:
    print("product: " + product)
    Product = f"product LIKE '%{product}%' "
    andCounter += 1
    hasProduct = True
else:
    Product = ""
if city != "" or city != None:
    print("city: " + city)
    City = f"city LIKE '%{city}%' "
    andCounter += 1
    hasCity = True
else:
    City = ""
if country != "" or country != None:
    Country = f"country LIKE '%{country}%' "
    andCounter += 1
    hasCountry = True
else:
    Country = ""
if email != "" or email != None:
    Email = f"email LIKE '%{email}%' "
    andCounter += 1
    hasEmail = True
else:
    Email = ""
if tel != "" or tel != None:
    Tel = f"tel LIKE '%{tel}%' "
    andCounter += 1
    hasTel = True
else:
    Tel = ""

如果有帮助,我让 if 语句生成一个变量 True 如果 if 语句运行,然后我打印出来,这些就是结果

Has IP: True
has Port: True
Has Domain: True
Has Formated Domain: True
hasASN: False
hasISP: True
hasOrginization: True
hasTag: True
hasProduct: True
hasCity: True
hasCountry: True
hasEmail: True
hasTel: True

我尝试通过以下方式验证参数是否 none:

@app.route("/test",methods=["GET"]) 
def test():
  emptyvalues = ["", "''", " ", "' '", None, '""', '" "']
  data = request.args
  if "ip" in data and data["ip"] not in emptyvalues:
    hasIP = True
  else:
    hasIP = False
  if "port" in data and data["port"] not in emptyvalues:
    hasPort = True
  else:
    hasPort = False

  print(hasIP, hasPort)
  print(data)
  return 'hello'

我用过

/test?ip=123&port=&domain=&formated_domain=&asn=&isp=&orginization=&tag=&product=&city=i&country=u&email=&tel=

结果为

True
False
ImmutableMultiDict([('ip', '123'), ('port', ''), ('domain', ''), ('formated_domain', ''), ('asn', ''), ('isp', ''), ('orginization', ''), ('tag', ''), ('product', ''), ('city', 'i'), ('country', 'u'), ('email', ''), ('tel', '')])

您的代码使用“或”而不是“和”,这就是无效输入被传递为 True 的原因