Python Forum
REST API x.509 authentication
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
REST API x.509 authentication
#1
Hi, new poster here! Been working with Excel, VBA and PowerQuery for a few years now and really wondered what's all the fuss about Python. I work a lot with REST-based API-s as a data consumer/analyst (HTTP GET/POST calls). But looks like I'm stuck with a particular API and apparently time has come to widen my toolbox since I have run out of functionality with my previous stack.

I need to connect to a REST-based API and get a ISO 20022 XML format data back - would work just fine with Excel / PowerQuery, however - the API uses x.509 certificate based authentication which PowerQuery / Excel VBA cannot do.

Is this something Python could comfortably handle? I'm really taking my very first steps in Python world, so any guidance, code samples or relevant blog posts etc would be greatly appreciated!
Reply
#2
Requests can do this.
Authentication with an X.509 certificate by specifying the path to the cert and key in your request.
requests.get('https://example.com', cert=('/path/client.cert', '/path/client.key'))
A example how Requests work,using httpbin Request & Response Service.
import requests

custom_header = {'user-agent': 'customUserAgent'}
payload = {'website': 'python-forum.io'}
url = 'http://httpbin.org/get'
response = requests.get(url, headers=custom_header, params=payload)
>>> response.status_code
200
>>> 
>>> response.json()
{'args': {'website': 'python-forum.io'},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Host': 'httpbin.org',
             'User-Agent': 'customUserAgent',
             'X-Amzn-Trace-Id': 'Root=1-620aefc7-6a0e69062220969551fe5a6f'},
 'origin': '83.143.86.74',
 'url': 'http://httpbin.org/get?website=python-forum.io'}
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020