[Koha-devel] REST API integration issues .

Esharat Mia esharat at esharat.me
Tue Mar 15 18:34:01 CET 2022


Thanks for your response . I add space after Bearer but same error. response code 401.










---- On Tue, 15 Mar 2022 22:48:33 +0600 Jonathan Druart <jonathan.druart at bugs.koha-community.org> wrote ----



'Authorization': 'Bearer' +access_token 
 
Add a space after "Bearer" 
 
'Authorization': 'Bearer ' +access_token 
 
Le mar. 15 mars 2022 à 17:10, Esharat Mia <mailto:esharat at esharat.me> a écrit : 
> 
> 
> Dear All, 
> 
> Here is my python code for testing REST API - 
> 
> import requests 
> import json 
> data = { 
> "client_id": "52ba706f-902c-4208-b28d-c05df607f3c4", 
> "client_secret": "de1c0400-ec02-4143-972e-752931968aed", 
> "grant_type": "client_credentials", 
> 
> } 
> headers = { 
> 'Content_type': 'application/x-www-form-urlencoded' 
> } 
> response = requests.post("http://localhost:8080/api/v1/oauth/token", data=data, headers=headers) 
> 
> credentials = response.json() 
> print(credentials) 
> access_token = credentials['access_token'] 
> print("Access_token: ",access_token) 
> auth2 = { 
> 'Authorization': 'Bearer' +access_token 
> } 
> response= requests.get("http://localhost:8080/api/v1/patrons", headers=auth2 
> ) 
> 
> print(response) 
> 
> When I run this code , I get access_token . Then I use this access token  and try retrieve data. But getting authentication failure or response code 401 . My output below - 
> 
> 
>  (base) esharat at esharat-desktop:~/Desktop/Library$ python3 test.py 
> 
> {'access_token': 'MTY0NzM2MDQ3Mi00MzgwNzctMC42OTA2NTM5MzA1MDgxODQtM0pTSTcwdUhGcVdzaTlUUnhGcGVDaTFmaVg3Nm9v', 'expires_in': 3600, 'token_type': 'Bearer'} 
> 
> Access_token:  MTY0NzM2MDQ3Mi00MzgwNzctMC42OTA2NTM5MzA1MDgxODQtM0pTSTcwdUhGcVdzaTlUUnhGcGVDaTFmaVg3Nm9v 
> 
> <Response [401]> 
> 
> Thanks in advance . 
> 
> 
> _______________________________________________ 
> Koha-devel mailing list 
> mailto:Koha-devel at lists.koha-community.org 
> https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel 
> website : https://www.koha-community.org/ 
> git : https://git.koha-community.org/ 
> bugs : https://bugs.koha-community.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20220315/09033cbd/attachment.htm>


More information about the Koha-devel mailing list