Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
sama007
Contributor
Contributor

How to connect to the qlik engine api with python through a proxy (with windows authentication) ?

Hello,

I'm trying to connect to the qlik engine api with python but I can't. I read a post: https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-call-Qlik-Sense-Engine-API-with-P...
which looks very useful but unfortunately it doesn't work for me.
In my case I have to connect to a corporate proxy which complicates my task even more.

I tried to pass a proxy to my connection using websocket but it doesn't work (WebSocketProxyException(
websocket._exceptions.WebSocketProxyException: failed CONNECT via proxy status: 307).
https://websocket-client.readthedocs.io/en/latest/examples.html#connecting-through-a-proxy

I have no idea if I'm going in the right direction, do you have any resources to help me?

Labels (1)
  • API

2 Replies
Qlik_Administrator_Dude
Partner - Creator
Partner - Creator

Hello,

Could you post an example of your Code? Thank you very much.

This part of the WebSocet Documentation is very interesting.

Qlik_Administrator_Dude_0-1680780988738.png

 

sama007
Contributor
Contributor
Author

import websocket
import ssl
import json

proxy_host = "XXX.XX.XXX.XX" #proxy server IP
proxy_port = XXXX            #proxy server port
my_session = 'XXXX-XXX-XXX-XXX-XXXX'
host = 'XXXXX'
websocket_key = 'XXXXXXXXX'
usr = 'XXXXX'
pswd = 'XXXXXXXXXXX'

header = {
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
    'Cache-Control': 'no-cache',
    'Connection': 'Upgrade',
    'Cookie': 'X-Qlik-Session={my_session}',
    'Host': host,
    'Origin': f'https://{host}',
    'Pragma': 'no-cache',
    'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
    'Sec-WebSocket-Key': websocket_key,
    'Sec-WebSocket-Version': '13',
    'Upgrade': 'websocket',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36' ,  
}
ws = websocket.create_connection(
    f"wss://{host}/app/", sslopt={"cert_reqs": ssl.CERT_NONE},
    header=header,
    http_proxy_port=proxy_port,
    http_proxy_host = proxy_host,
    proxy_type="http",
    http_proxy_auth=(usr, pswd)
    )

ws.send(json.dumps({
    "handle": -1,
    "method": "GetDocList",
    "params": [],
    "outKey": -1,
    "id": 1
}))

result = ws.recv()

while result:
    result=ws.recv()
    y = json.loads(result)
    print(y)

ws.close()



since I can't move forward, I first copied the header from my browser (when I access api engine). I don't think this is the best way to do it but this is what I use to start