@@ -155,7 +155,7 @@ expires_in = 0
155155auth_url = f ' { RDP_HOST } /auth/oauth2/v1/token '
156156payload = f ' grant_type=password&username= { username} &client_id= { clientId} &password= { password} &takeExclusiveSignOnControl=True&scope=trapi '
157157try :
158- response = requests.post(auth_url,
158+ auth_response = requests.post(auth_url,
159159 headers = {' Content-Type' :' application/x-www-form-urlencoded' },
160160 data = payload,
161161 auth = (clientId, ' ' )
@@ -167,15 +167,15 @@ except requests.exceptions.RequestException as exp:
167167The next step is checking the authentication request result, then get the token information and assign them to local variables for the later use.
168168
169169``` Python
170- if response .status_code == 200 : # HTTP Status 'OK'
170+ if auth_response .status_code == 200 : # HTTP Status 'OK'
171171 print (' Authentication success' )
172- access_token = response .json()[' access_token' ]
173- refresh_token = response .json()[' refresh_token' ]
174- expires_in = int (response .json()[' expires_in' ])
172+ access_token = auth_response .json()[' access_token' ]
173+ refresh_token = auth_response .json()[' refresh_token' ]
174+ expires_in = int (auth_response .json()[' expires_in' ])
175175
176- if response .status_code != 200 :
177- print (f ' RDP authentication failure: { response .status_code} { response .reason} ' )
178- print (f ' Text: { response .text} ' )
176+ if auth_response .status_code != 200 :
177+ print (f ' RDP authentication failure: { auth_response .status_code} { auth_response .reason} ' )
178+ print (f ' Text: { auth_response .text} ' )
179179```
180180Now we have the access token information that can be used for further data requests.
181181
@@ -229,22 +229,22 @@ bucket_name = 'bulk-ESG'
229229CFS_url = f ' { RDP_HOST } /file-store/v1/packages?bucketName= { bucket_name} '
230230
231231try :
232- response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
232+ packageID_response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
233233except requests.exceptions.RequestException as exp:
234234 print (f ' Caught exception: { exp} ' )
235235
236- if response .status_code == 200 : # HTTP Status 'OK'
236+ if packageID_response .status_code == 200 : # HTTP Status 'OK'
237237 print (' Receive list Package IDs from RDP APIs' )
238238else :
239- print (f ' RDP APIs: CFS request failure: { response .status_code} { response .reason} ' )
240- print (f ' Text: { response .text} ' )
239+ print (f ' RDP APIs: CFS request failure: { packageID_response .status_code} { packageID_response .reason} ' )
240+ print (f ' Text: { packageID_response .text} ' )
241241```
242242You can check the example data response to see the example of PackageIds from the following code:
243243
244244``` Python
245245# Example of the first entry of package IDs
246246
247- print (json.dumps(response .json()[' value' ][0 ], sort_keys = True , indent = 2 , separators = (' ,' , ' :' )))
247+ print (json.dumps(packageID_response .json()[' value' ][0 ], sort_keys = True , indent = 2 , separators = (' ,' , ' :' )))
248248```
249249
250250Result:
@@ -288,15 +288,15 @@ packageId = '4037-e79c-96b73648-a42a-6b65ef8ccbd1'
288288CFS_url = f ' { RDP_HOST } /file-store/v1/file-sets?bucket= { bucket_name} &packageId= { packageId} '
289289
290290try :
291- response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
291+ fileSet_response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
292292except requests.exceptions.RequestException as exp:
293293 print (f ' Caught exception: { exp} ' )
294294
295- if response .status_code == 200 : # HTTP Status 'OK'
295+ if fileSet_response .status_code == 200 : # HTTP Status 'OK'
296296 print (' Receive FileSets list from RDP APIs' )
297297else :
298- print (f ' RDP APIs: CFS request failure: { response .status_code} { response .reason} ' )
299- print (f ' Text: { response .text} ' )
298+ print (f ' RDP APIs: CFS request failure: { fileSet_response .status_code} { fileSet_response .reason} ' )
299+ print (f ' Text: { fileSet_response .text} ' )
300300```
301301The FileSets response message from the API is as follows:
302302
@@ -346,16 +346,16 @@ Python Code:
346346CFS_url = f ' { RDP_HOST } /file-store/v1/file-sets?bucket= { bucket_name} &pageSize=2 '
347347
348348try :
349- response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
349+ fileSet_response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
350350except requests.exceptions.RequestException as exp:
351351 print (f ' Caught exception: { exp} ' )
352352
353353
354- if response .status_code == 200 : # HTTP Status 'OK'
354+ if fileSet_response .status_code == 200 : # HTTP Status 'OK'
355355 print (' Receive list Package IDs from RDP APIs' )
356356else :
357- print (f ' RDP APIs: CFS request failure: { response .status_code} { response .reason} ' )
358- print (f ' Text: { response .text} ' )
357+ print (f ' RDP APIs: CFS request failure: { fileSet_response .status_code} { fileSet_response .reason} ' )
358+ print (f ' Text: { fileSet_response .text} ' )
359359```
360360Now we get 2 entries per request from the API as we set via ``` pageSize=2 ``` parameter:
361361
@@ -418,15 +418,15 @@ if '@nextLink' in response.json():
418418 CFS_url = f ' { RDP_HOST }{ next_link} '
419419
420420 try :
421- response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
421+ fileSet_response = requests.get(CFS_url , headers = {' Authorization' : f ' Bearer { access_token} ' })
422422 except requests.exceptions.RequestException as exp:
423423 print (f ' Caught exception: { exp} ' )
424424
425- if response .status_code == 200 : # HTTP Status 'OK'
425+ if fileSet_response .status_code == 200 : # HTTP Status 'OK'
426426 print (' Receive list Package IDs from RDP APIs' )
427427 else :
428- print (f ' RDP APIs: CFS request failure: { response .status_code} { response .reason} ' )
429- print (f ' Text: { response .text} ' )
428+ print (f ' RDP APIs: CFS request failure: { fileSet_response .status_code} { fileSet_response .reason} ' )
429+ print (f ' Text: { fileSet_response .text} ' )
430430```
431431
432432Result:
@@ -499,17 +499,17 @@ file_id = response.json()['value'][0]['files'][1] #'4c35-1775-c1a590ea-8376-ac6c
499499FileID_url = f ' { RDP_HOST } /file-store/v1/files/ { file_id} /stream?doNotRedirect=true '
500500
501501try :
502- response = requests.get(FileID_url, headers = {' Authorization' : f ' Bearer { access_token} ' })
502+ fileID_response = requests.get(FileID_url, headers = {' Authorization' : f ' Bearer { access_token} ' })
503503except requests.exceptions.RequestException as exp:
504504 print (f ' Caught exception: { exp} ' )
505505
506- if response .status_code == 200 : # HTTP Status 'OK'
506+ if fileID_response .status_code == 200 : # HTTP Status 'OK'
507507 print (' Receive File URL from RDP APIs' )
508508else :
509- print (f ' RDP APIs: CFS request failure: { response .status_code} { response .reason} ' )
509+ print (f ' RDP APIs: CFS request failure: { fileID_response .status_code} { fileID_response .reason} ' )
510510 print (f ' Text: { response.text} ' )
511511
512- file_url = response .json()[' url' ]
512+ file_url = fileID_response .json()[' url' ]
513513print (file_url)
514514```
515515The File URL is in the ``` url ``` attribute of the response message.
@@ -528,30 +528,30 @@ That brings us to download the file. Based on the S3 ```file_url``` above, the a
528528Python code:
529529
530530``` Python
531- # step 5 - Downlaod file
531+ # step 5 - Download file
532532import polling2
533533
534534zipfilename = file_url.split(" ?" )[0 ].split(" /" )[- 1 ].replace(" %3A" ," _" )
535535print (f ' Downloading File { zipfilename} ... ' )
536536
537- def test_result (response ):
538- return response .status_code == 200
537+ def test_result (_response ):
538+ return _response .status_code == 200
539539
540540try :
541- response = polling2.poll(lambda : requests.get(file_url),
541+ bulkFile_response = polling2.poll(lambda : requests.get(file_url),
542542 step = 10 ,
543543 poll_forever = True ,
544544 check_success = test_result)
545545except requests.exceptions.RequestException as exp:
546546 print (f ' Caught exception: { exp} ' )
547547
548- if response .status_code == 200 : # HTTP Status 'OK'
548+ if bulkFile_response .status_code == 200 : # HTTP Status 'OK'
549549 print (' Receive File Successfully' )
550- open (zipfilename, ' wb' ).write(response .content)
550+ open (zipfilename, ' wb' ).write(bulkFile_response .content)
551551 print (f ' { zipfilename} Saved ' )
552552else :
553- print (f ' RDP APIs: Request file failure: { response .status_code} { response .reason} ' )
554- print (f ' Text: { response .text} ' )
553+ print (f ' RDP APIs: Request file failure: { bulkFile_response .status_code} { bulkFile_response .reason} ' )
554+ print (f ' Text: { bulkFile_response .text} ' )
555555```
556556
557557Result:
@@ -601,24 +601,26 @@ Python code:
601601# Send HTTP Request
602602auth_url = f ' { RDP_HOST } /auth/oauth2/v1/token '
603603payload = f ' grant_type=refresh_token&client_id= { clientId} &refresh_token= { refresh_token} '
604+ auth_response = None
605+
604606try :
605- response = requests.post(auth_url,
607+ auth_response = requests.post(auth_url,
606608 headers = {' Content-Type' :' application/x-www-form-urlencoded' },
607609 data = payload,
608610 auth = (clientId, ' ' )
609611 )
610612except requests.exceptions.RequestException as exp:
611613 print (f ' Caught exception: { exp} ' )
612614
613- if response .status_code == 200 : # HTTP Status 'OK'
615+ if auth_response .status_code == 200 : # HTTP Status 'OK'
614616 print (' Refresh Token success' )
615- access_token = response .json()[' access_token' ]
616- refresh_token = response .json()[' refresh_token' ]
617- expires_in = int (response .json()[' expires_in' ])
617+ access_token = auth_response .json()[' access_token' ]
618+ refresh_token = auth_response .json()[' refresh_token' ]
619+ expires_in = int (auth_response .json()[' expires_in' ])
618620
619- if response .status_code != 200 :
620- print (f ' RDP authentication failure: { response .status_code} { response .reason} ' )
621- print (f ' Text: { response .text} ' )
621+ if auth_response .status_code != 200 :
622+ print (f ' RDP authentication failure: { auth_response .status_code} { auth_response .reason} ' )
623+ print (f ' Text: { auth_response .text} ' )
622624```
623625
624626### Step 7: Revoke Token to ending the session.
@@ -658,8 +660,10 @@ clientId_base64 = base64_bytes.decode('ascii')
658660# Send HTTP Request
659661auth_url = f ' { RDP_HOST } /auth/oauth2/v1/revoke '
660662payload = f ' token= { access_token} '
663+ auth_response = None
664+
661665try :
662- response = requests.post(auth_url,
666+ auth_response = requests.post(auth_url,
663667 headers = {
664668 ' Content-Type' :' application/x-www-form-urlencoded' ,
665669 ' Authorization' : f ' Basic { clientId_base64} '
@@ -670,11 +674,11 @@ try:
670674except requests.exceptions.RequestException as exp:
671675 print (f ' Caught exception: { exp} ' )
672676
673- if response .status_code == 200 : # HTTP Status 'OK'
677+ if auth_response .status_code == 200 : # HTTP Status 'OK'
674678 print (' Revoke Token success' )
675- if response .status_code != 200 :
676- print (f ' RDP authentication failure: { response .status_code} { response .reason} ' )
677- print (f ' Text: { response .text} ' )
679+ if auth_response .status_code != 200 :
680+ print (f ' RDP authentication failure: { auth_response .status_code} { auth_response .reason} ' )
681+ print (f ' Text: { auth_response .text} ' )
678682```
679683That’s all I have to say about the CFS API workflow.
680684
@@ -824,7 +828,7 @@ And much more on the [Developer Portal](https://developers.lseg.com/en) website.
824828
825829For further details, please check out the following resources:
826830
827- - [RDP APIs page](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) on the [LSEG Developer Community](https://developers.lseg.com/) website.
831+ - [Delivery Platform ( RDP) APIs page](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) on the [LSEG Developer Community](https://developers.lseg.com/) website.
828832- [RDP APIs Playground page](https://apidocs.refinitiv.com/Apps/ApiDocs).
829833- [RDP APIs: Introduction to the Request-Response API](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#introduction-to-the-request-response-api).
830834- [RDP APIs: Authorization - All about tokens](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis/tutorials#authorization-all-about-tokens).
0 commit comments