...tion notes
###Step 3: send an on demand extraction request using the received token
requestUrl='https://selectapi.datascope.refinitiv.com/RestApi/v1/Extractions/ExtractRaw'
requestHeaders={
'Prefer':'respond-async',
'Content-Type':'application/json',
'Authorization': 'token ' + token
}
requestBody={
"ExtractionRequest": {
"@odata.type": "#DataScope.Select.Api.Extractions.ExtractionRequests.TickHistoryTimeAndSalesExtractionRequest",
"ContentFieldNames": [
"Trade - Price",
"Trade - Volume",
"Trade - Exchange Time"
],
'IdentifierList': {
'@odata.type': '#DataScope.Select.Api.Extractions.ExtractionRequests.InstrumentIdentifierList',
'InstrumentIdentifiers': instrumentList,
},
'Condition': {
"MessageTimeStampIn": "GmtUtc",
"ApplyCorrectionsAndCancellations": "false",
"ReportDateRangeType": "Range",
"QueryStartDate": "2016-09-29T00:00:00.000Z",
"QueryEndDate": "2016-09-29T12:00:00.000Z",
"DisplaySourceRIC": "true"
}
}
}
print('sending the extraction request for the list of option RICs')
r3 = requests.post(requestUrl, json=requestBody, headers=requestHeaders)
#Display the response status, and the location url to use to get the status of the extraction request
#Initial response status after approximately 30 seconds wait will be 202
print ('response status from the extraction request = ' + str(r3.status_code))
#If there is a client side or server side error, display the error information and exit
if r3.status_code >= 400 :
print(r3.text.encode('ascii', 'ignore'))
sys.exit()
#Step 4: poll the status of the request using received location URL, and get the jobId and extraction notes
requestUrl = r3.headers['location']
requestHeaders={
'Prefer': 'respond-async',
'Content-Type': 'application/json',
'Authorization': 'token ' + token
}
r4 = requests.get(requestUrl, headers=requestHeaders)
#The extraction may take a long time for large content sets
#While the extraction is being processed on the server the request status we receive is 202
#We're polling the service for the status every 30 seconds until the status is 200
while r4.status_code == 202 :
r4 = requests.get(requestUrl, headers=requestHeaders)
print (str(dt.datetime.now()) + ' Server is still processing the extraction. Checking the status again in 30 seconds')
time.sleep(30)
---run the code and then the error code as below, please help.
sending the extraction request for the list of option RICs
response status from the extraction request = 200
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-36-ed1cf426d309> in <module>
46 #Step 4: poll the status of the request using received location URL, and get the jobId and extraction notes
47
---> 48 requestUrl = r3.headers['location']
49
50 requestHeaders={
C:\ProgramData\Anaconda3\lib\site-packages\requests\structures.py in __getitem__(self, key)
50
51 def __getitem__(self, key):
---> 52 return self._store[key.lower()][1]
53
54 def __delitem__(self, key):
KeyError: 'location'