(lots of requests in the title, I know)
With Fiddler I got a request working. It does exactly what I want. When I try to reproduce it in python, it doesn't work. this is the Fiddler request:
POST https://ichthus.zportal.nl/api/v3/oauth/ HTTP/1.1
Host: ichthus.zportal.nl
Content-Type: application/x-www-form-urlencoded
username=138777&password=XXXXX&client_id=OAuthPage&redirect_uri=%2Fmain%2F&scope=&state=4E252A&response_type=code&tenant=ichthus
and this is the Python Requests code I tried:
import requests
endpoint = "https://ichthus.zportal.nl/api/v3/oauth/"
authData = {
'username': '138777',
'password': 'XXXXX',
'client_id': 'OAuthPage',
'redirect_uri': '/main/',
'scope': '',
'state': '4E252A',
'response_type': 'code',
'tenant': 'ichthus',
}
header = {
'Host': 'ichthus.zportal.nl',
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post(endpoint, data=authData, headers=header)
print response.headers
print response.status_code
With Request to Code I managed to get it to a python URLlib2 request. But I have never used URLlib before and I was wondering if it could be converted to a Python Requests request. This is the Python URLlib2 code:
def make_requests():
response = [None]
responseText = None
if(request_ichthus_zportal_nl(response)):
responseText = read_response(response[0])
response[0].close()
def request_ichthus_zportal_nl(response):
response[0] = None
try:
req = urllib2.Request("https://ichthus.zportal.nl/api/v3/oauth/")
req.add_header("Content-Type", "application/x-www-form-urlencoded")
body = "username=138777&password=XXXX&client_id=OAuthPage&redirect_uri=%2Fmain%2F&scope=&state=4E252A&response_type=code&tenant=ichthus"
response[0] = urllib2.urlopen(req, body)
except urllib2.URLError, e:
if not hasattr(e, "code"):
return False
response[0] = e
except:
return False
return True