我正在使用 django 进行测试并创建了一个简单的应用程序,该应用程序将返回有关给定注册号的一些详细信息。我将这些详细信息与我的 shopify 商店中的产品列表进行了比较,并且我想返回符合条件的过滤产品。
但是 Heroku 服务时出现服务器错误 500。我找不到日志有任何问题。
2021-07-31T20:43:09.115353+00:00 heroku[web.1]: Starting process with command `gunicorn APImat.wsgi --log-file -`
2021-07-31T20:43:11.691200+00:00 app[web.1]: [2021-07-31 20:43:11 +0000] [4] [INFO] Starting gunicorn 20.1.0
2021-07-31T20:43:11.692898+00:00 app[web.1]: [2021-07-31 20:43:11 +0000] [4] [INFO] Listening at: http://0.0.0.0:51130 (4)
2021-07-31T20:43:11.693005+00:00 app[web.1]: [2021-07-31 20:43:11 +0000] [4] [INFO] Using worker: sync
2021-07-31T20:43:11.697003+00:00 app[web.1]: [2021-07-31 20:43:11 +0000] [7] [INFO] Booting worker with pid: 7
2021-07-31T20:43:11.759836+00:00 app[web.1]: [2021-07-31 20:43:11 +0000] [8] [INFO] Booting worker with pid: 8
2021-07-31T20:43:12.235949+00:00 heroku[web.1]: State changed from starting to up
2021-07-31T20:43:13.000000+00:00 app[api]: Build succeeded
2021-07-31T20:43:29.513759+00:00 app[web.1]: VOLKSWAGEN
2021-07-31T20:43:29.513867+00:00 app[web.1]: SHARAN SEL BLUE TECH TDI S-A
2021-07-31T20:43:29.513923+00:00 app[web.1]: 0
2021-07-31T20:43:29.911010+00:00 app[web.1]: 6682466025621
2021-07-31T20:43:30.272828+00:00 app[web.1]: 6714350698645
2021-07-31T20:43:30.613893+00:00 app[web.1]: 6720035750037
2021-07-31T20:43:30.987627+00:00 app[web.1]: 6734793212053
2021-07-31T20:43:31.383095+00:00 app[web.1]: 6793971859605
2021-07-31T20:43:31.671587+00:00 app[web.1]: 6973133750421
2021-07-31T20:43:31.917019+00:00 app[web.1]: 10.41.181.68 - - [31/Jul/2021:20:43:31 +0000] "GET /KM12AKK/ HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
2021-07-31T20:43:31.919827+00:00 heroku[router]: at=info method=GET path="/KM12AKK/" host=fazaljarral-gcm.herokuapp.com request_id=724a817e-7765-4639-953a-bcbf607c21d0 fwd="103.20.0.219" dyno=web.1 connect=1ms service=3213ms status=500 bytes=348 protocol=https
2021-07-31T20:43:32.631559+00:00 app[web.1]: 10.41.181.68 - - [31/Jul/2021:20:43:32 +0000] "GET /favicon.ico HTTP/1.1" 301 0 "https://fazaljarral-gcm.herokuapp.com/KM12AKK/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
2021-07-31T20:43:32.634341+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=fazaljarral-gcm.herokuapp.com request_id=4943467f-7c3a-4ec7-a39a-84726088367a fwd="103.20.0.219" dyno=web.1 connect=1ms service=102ms status=301 bytes=206 protocol=https
2021-07-31T20:43:33.346045+00:00 app[web.1]: 10.41.181.68 - - [31/Jul/2021:20:43:33 +0000] "GET /favicon.ico/ HTTP/1.1" 500 145 "https://fazaljarral-gcm.herokuapp.com/KM12AKK/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
2021-07-31T20:43:33.348888+00:00 heroku[router]: at=info method=GET path="/favicon.ico/" host=fazaljarral-gcm.herokuapp.com request_id=4adda44b-510e-4a92-a8f0-d8def63ae7e4 fwd="103.20.0.219" dyno=web.1 connect=1ms service=436ms status=500 bytes=348 protocol=https
当我在本地运行它时,它工作得很好。如果我们点击主页,该应用程序也已部署并且正在运行。例如 fazaljarral-gcm.herokuapp.com
,但如果我要搜索 fazaljarral-gcm.herokuapp.com\KM12AKK\
之类的注册号,则会引发错误。
def search_view(request,search_num):
reg_num = search_num
url = "https://uk1.ukvehicledata.co.uk/api/datapackage/VehicleData?v=2&auth_apikey=&key_VRM={num}".format(num=reg_num)
response = requests.get(url)
ResponseJSON = response.json()
make = ResponseJSON.get("Response").get("DataItems").get("ClassificationDetails").get("Dvla").get("Make")
model = ResponseJSON.get("Response").get("DataItems").get("ClassificationDetails").get("Dvla").get("Model")
print(make)
print(model)
obj = {
"make" : make,
"model" : model
}
active = True;
filtered_product = []
sinceId = 0;
while (active):
print(sinceId)
products_url = "https://api:pswrd@shop_name.myshopify.com/admin/api/2021-07/products.json?limit=250&since_id={id}".format(
id=sinceId)
prod_response = requests.get(products_url)
ResponseJSON_prod = prod_response.json()
product_list = ResponseJSON_prod.get("products")
if len(product_list) <= 0:
active = False
else:
sinceId = product_list[-1].get("id")
# print(product_list)
for item in product_list:
# if item == len(product_list) - 1:
# sinceId = item.get("id")
title = item.get("title")
vendor = item.get("vendor")
handle = item.get("handle")
tags = item.get("tags")
if item.get("image") is not None:
img_src = item.get("image").get("src")
price = item.get("variants")[0].get("price")
# product = {
# "title" : title,
# "vendor" : vendor,
# "handle" : handle,
# "tags" : tags,
# "img_src" : img_src,
# "price" : price
# }
if (make in title):
filtered_product.append(item)
context = {"obj" : obj , "prod_list" : product_list }
if len(filtered_product < 1):
return HttpResponse("Product Not Found")
response = JsonResponse(
filtered_product,
safe= False
)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET, OPTIONS"
response["Access-Control-Max-Age"] = "1000"
response["Access-Control-Allow-Headers"] = "X-Requested-With, Content-Type"
return response