hsp request issues

128 views
Skip to first unread message

Brian

unread,
Dec 31, 2016, 11:26:19 AM12/31/16
to A gathering place for the Open Rail Data community
Hi,

I'm just starting out I'm running the following python script against the hsp service

import requests

jsonRequest = """{from_loc:"VIC",to_loc:"BTN",from_time:"0700",to_time:"0800",from_date:"2016-12-27",to_date:"2016-12-27",days:"WEEKDAY"}"""
resp = requests.post("https://hsp-prod.rockshore.net/api/v1/serviceMetrics/", auth=(
<username removed>,<password removed>), json=jsonRequest)
print(resp._content)

but am getting the error 

{"my_journey_errors":{"errors":["Could not read document: Can not instantiate value of type [simple type, class com.caci.hsp.myjourney.api.ServiceMetricsRequestSchema] from String value ('{from_loc:\"VIC\",to_loc:\"BTN\",from_time:\"0700\",to_time:\"0800\",from_date:\"2016-12-27\",to_date:\"2016-12-27\",days:\"WEEKDAY\"}'); no single-String constructor/factory method"]}}

Can anyone shed any light on what is wrong with my request.

Thanks,

Brian


Chris Northwood

unread,
Dec 31, 2016, 11:50:20 AM12/31/16
to A gathering place for the Open Rail Data community
First thoughts are that you aren't sending valid JSON. You're instead sending a string which looks like a Python dictionary. You probably want to make jsonRequest actually be a dictionary rather than a string when you pass it into the json object, ie,

import requests

jsonRequest = {from_loc:"VIC",to_loc:"BTN",from_time:"0700",to_time:"0800",from_date:"2016-12-27",to_date:"2016-12-27",days:"WEEKDAY"}
resp = requests.post("https://hsp-prod.rockshore.net/api/v1/serviceMetrics/", auth=(
<username removed>,<password removed>), json=jsonRequest)
print(resp._content)

--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-talk+unsubscribe@googlegroups.com.
To post to this group, send email to openraildata-talk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian

unread,
Dec 31, 2016, 12:24:25 PM12/31/16
to A gathering place for the Open Rail Data community
thanks Chris
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-t...@googlegroups.com.
To post to this group, send email to openrail...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages