question

Upvotes
Accepted
26 1 2 5

Is there a way to pass a proxy as a parameter in refinitiv.data library (Python)?

Hi,


Similar to this question from 2 years ago, I want to connect to the refinitiv.data library via a proxy server. This is because I need to run rd.get_data requests from an internal private server with, let's just say, highly strict network configurations. Right now, running rd.get_data() the regular way will return an empty dataframe and sometimes this error:

"An error occurred while requesting URL('http://localhost:9060/api/udf').
ReadError('[WinError 10053] An established connection was aborted by the software in your host machine')". 


My question is - is it now possible to configure my session to use a proxy server? If yes, how? If no, any alternatives?


Edit: Correction in title


Thanks and regards,

RC

pythonrefinitiv-data-librariesrefinitiv-dataplatform-libraries
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
78.6k 248 52 74

@RC Da Cola

Thanks for reaching out to us.

As I knew, currently, you need to set a proxy via environment variables.

The RD library uses the httpx Python lib which uses these variables: https://www.python-httpx.org/environment_variables/#http_proxy-https_proxy-all_proxy.

For example:

import os
os.environ['HTTP_PROXY']="http://127.0.0.1:8080"
os.environ['HTTPS_PROXY']="http://127.0.0.1:8080"
os.environ['SSL_CERT_FILE'] = "C:\\Users\\U8009686\\.mitmproxy\\mitmproxy-ca.pem"

I hope that this information is of help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @Jirapongse,


This seems to work for platform sessions but not desktop sessions. (For others' reference, please see code snippet below). Not sure if this is just specific to me but I was hoping both options to work. Regardless, I'll accept this as the answer. Thank you very much!


Desktop Session

import refinitiv.data as rd
import os

os.environ["HTTP_PROXY"] = "YOUR_PROXY"
os.environ["HTTPS_PROXY"] = "YOUR_PROXY"

appKey = "YOUR_APPKEY"
rd.open_session(app_key=appKey)

df = rd.get_data("MSFT.O", ["TR.ClosePrice"])

print(df)
rd.close_session()

Returns:

Empty DataFrame
Columns: []
Index: []


Platform Session

import refinitiv.data as rd
import os

os.environ["HTTP_PROXY"] = "YOUR_PROXY"
os.environ["HTTPS_PROXY"] = "YOUR_PROXY"

session = rd.session.platform.Definition(
    app_key = "YOUR_APPKEY", 
    grant = rd.session.platform.GrantPassword(
        username = "YOUR_USERNAME", 
        password = "YOUR_PASSWORD"
    )
).get_session()

rd.session.set_default(session)

session.open()

df = rd.get_data("MSFT.O", ["TR.ClosePrice"])
print(df)

session.close()

Returns:

  Instrument  Close Price
0     MSFT.O       308.65
Upvotes
78.6k 248 52 74

@RC Da Cola

The desktop session gets the data from the localhost (127.0.0.1). I am not sure if the proxy can connect to the localhost that runs a desktop application.

If I set a proxy on my local machine and use it with the desktop session, it works fine.

1683597735540.png


1683597735540.png (30.5 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.