Anaconda Toolbox in excel runtime (v1.2.0 build 144) does not include the ssl module?

Hi there,

When I use this code in the excel version:

import ssl
print(ssl.OPENSSL_VERSION)

It gives following error:

Traceback (most recent call last):
File “‘DATA’!B18”, line 1, in
import ssl
ModuleNotFoundError: No module named ‘ssl’

My question is this to do with Anaconda Toolbox not able to request data from websites like FRED? I have installed “requests” and fredapi libraries but when requesting FRED data, I just get errors.

For instance when requesting

import requests
import pandas as pd

api_key = “Key here”
series_list = [“WSHOMCB”, “WRESBAL”, “RRPONTSYD”]

frames =
for series_id in series_list:
url = f"https://api.stlouisfed.org/fred/series/observations?series_id={series_id}&api_key={api_key}&file_type=json"
response = requests.get(url)
obs = response.json()[‘observations’]
df = pd.DataFrame(obs)[[‘date’, ‘value’]]
df[‘value’] = pd.to_numeric(df[‘value’], errors=‘coerce’)
df[‘date’] = pd.to_datetime(df[‘date’])
df[‘SeriesID’] = series_id
frames.append(df)

final = pd.concat(frames, ignore_index=True)
pivoted = final.pivot(index=“date”, columns=“SeriesID”, values=“value”)
pivoted.tail()

This comes out with series of errors in the anaconda toolbox, but works fine in jupiter notebook.

Thank you for your time.

HI @Repop, thanks for your question.

Anaconda Code is an Office add-in. This means that it runs Python using pyscript in a browser inside Excel. When you make an http request from a browser to an API endpoint, the endpoint may have Cross-Origin Resource Sharing (CORS) restrictions limiting what origins it will receive requests from. In short, this is a security feature implemented by the API endpoint (and most API endpoints that can sometimes prevent issuing requests from browsers). The reason it works from Jupyter is that Jupyter is not a web browser.

The way around this is to use an API proxy server that receives the request from the add-in and forwards it to the endpoint.

We are looking into ways to make this process easier for Anaconda Code users.

Thank you.

I am myself not expert in IT, just wanting to pull FRED data to excel using the add-in for convenience. How does this work: “The way around this is to use an API proxy server that receives the request from the add-in and forwards it to the endpoint.”

I assume I need IT support from my company to do above. Any guidance on this would be helpful. It sounds more like I will have to wait for your update on this toolbox :slight_smile: