python&的关键错误App Engine

时间:2015-03-26 19:21:14

标签: python json google-app-engine arcgis

我正在App Engine和Python上开发一个应用程序。这个应用程序旨在创建到镇上几个点的路线。要创建此路由,我将调用对Arcgis服务的请求。完成后,我需要检查请求的状态并获得带有结果的JSON。我用以下方法检查这些结果:

def store_route(job_id, token):
    import requests, json
    #Process stops result and store it as json in stops_response
    stops_url = "https://logistics.arcgis.com/arcgis/rest/services/World/VehicleRoutingProblem/GPServer/SolveVehicleRoutingProblem/jobs/"
    stops_url = stops_url+str(job_id)+"/results/out_stops?token="+str(token)+"&f=json"
    stops_r = requests.get(stops_url)
    stops_response = json.loads(stops_r.text)
    #Process routes result and store it as json in routes_response
    routes_url = "https://logistics.arcgis.com/arcgis/rest/services/World/VehicleRoutingProblem/GPServer/SolveVehicleRoutingProblem/jobs/"
    routes_url = routes_url+str(job_id)+"/results/out_routes?token="+str(token)+"&f=json"
    routes_r = requests.get(routes_url)
    routes_response = json.loads(routes_r.text)
    from routing.models import ArcGisJob, DeliveryRoute
    #Process each route from response
    processed_routes = []
    for route_info in routes_response['value']['features']:
        print route_info
        route_name = route_info['attributes']['Name']
        coordinates = route_info['geometry']['paths']
        coordinates_json = {"coordinates": coordinates}
        #Process stops from each route
        stops = []
        for route_stops in stops_response['value']['features']:
            if route_name == route_stops['attributes']['RouteName']:
                stops.append({"Name": route_stops['attributes']['Name'], 
                                "Sequence": route_stops['attributes']['Sequence']})
        stops_json = {"content": stops}
        #Create new Delivery Route object
        processed_routes.append(DeliveryRoute(name=route_name,route_coordinates=coordinates_json, stops=stops_json))
    #insert a new Job table entry with all processed routes
    new_job = ArcGisJob(job_id=str(job_id), routes=processed_routes)
    new_job.put()

正如您所看到的,我的代码所做的实际上是访问服务返回的JSON并解析它以获取我感兴趣的内容。问题是我得到以下输出:

{u'attributes': {
u'Name': u'ruta_4855443348258816',
... 
u'StartTime': 1427356800000}, 
u'geometry': {u'paths': [[[-100.37766063699996, 25.67669987000005],
...
[-100.37716999999998, 25.67715000000004], 
[-100.37766063699996, 25.67669987000005]]]}}

ERROR    2015-03-26 19:02:58,405 handlers.py:73] 'geometry'
Traceback (most recent call last):
 File "/Users/Vercetti/Dropbox/Logyt/Quaker Routing/logytrouting/routing/handlers.py", line 68, in get
  arc_gis.store_route(job_id, token)
  File "/Users/Vercetti/Dropbox/Logyt/Quaker Routing/logytrouting/libs/arc_gis.py", line 150, in store_route
    coordinates = route_info['geometry']['paths']
KeyError: 'geometry'
ERROR    2015-03-26 19:02:58,412 BaseRequestHandler.py:51] Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/Users/Vercetti/Dropbox/Logyt/Quaker Routing/logytrouting/routing/handlers.py", line 68, in get
    arc_gis.store_route(job_id, token)
   File "/Users/Vercetti/Dropbox/Logyt/Quaker Routing/logytrouting/libs/arc_gis.py", line 150, in store_route
    coordinates = route_info['geometry']['paths']
KeyError: 'geometry'

返回的实际JSON有更多的信息,但我只是写了一小部分,所以你可以看到有一个'几何'键。知道为什么我会得到这个错误吗?

0 个答案:

没有答案