According to the docs, the first parameter should be appID
, not apiID
as you have it.
Equivilent of -d in curl with requests in python
Domanda
Right now I am using the OC Transpo API (http://www.octranspo1.com/developers/documentation) in my python application.
For my requests to their API to retrieve data I have this
class OcTranspoGetter:
#import credentials from file, my credentials are not in sample file,
#they can be gotten from http://www.octranspo1.com/developers/
def __init__(self):
credFile = open('../config/logins.ser')
credentials = pickle.load(credFile)
self.apiID = credentials['apiLogin']['apiID']
#self.apiKey = credentials['apiLogin']['apiKey']
self.payLoad = {'apiID':self.apiID,'apiKey':self.apiKey}
print self.payLoad
#Get live data
def getLiveData(self,bus,stop):
self.payLoad['stopNum'] = stop
soapData = requests.post('https://api.octranspo1.com/v1.2/GetRouteSummaryForStop',data = self.payLoad)
return soapData
Though when I run the code with:
sys.path.insert(0, 'modules')
from octranspo import OcTranspoGetter
import utilities
octranspo = OcTranspoGetter();
soapData = octranspo.getLiveData('3017','94')
print soapData.text
I get the error Error: application with id="" was not found
From this and url that is returned from soapData, it looks like that request.post() is using a get method still for requesting to the API. The service requires post, as the documents on it say to use the curl -d command. From what I have seen of the request docs (http://docs.python-requests.org/en/latest/user/quickstart) what I am doing should make a post request, but it is not. Is there something I am missing in the documentation?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow