logo
search
Data Import & Export

Fix Python in Excel Cannot Connect to APIs or the Internet

Nimra MalikNimra Malik Sep 29, 2026 869 views

Question details

Users need to resolve proxy, tunnel, or 400-type errors that occur when attempting to connect to external APIs or the internet using Python in Excel.

How to Fix Python in Excel Cannot Connect to APIs or the Internet
Product
Microsoft Excel
Device & OS
not provided
Scenario
Writing Python scripts directly inside an Excel workbook to fetch real-time data from external web APIs or internet sources.
Observed behavior
The connection fails and returns ProxyError or 400-type errors, despite the local network and system proxy settings functioning correctly.
Before you start

Verify that your computer has a stable, active internet connection and that you are signed into your Microsoft 365 account with an active license.

Solution 1Recommended

Use Power Query to Import Data First

Since Python in Excel blocks outbound internet requests, use Power Query to fetch the API data and load it into your workbook before analyzing it with Python.

Python in Excel runs in a secure, isolated cloud container provided by Microsoft. To protect user security, this environment intentionally blocks all outbound internet calls.

Attempting to use Python libraries like 'requests' or 'urllib' to call external APIs will result in a ProxyError, tunnel error, or 400-type error, regardless of your local network configuration. The standard workaround is separating the data import from the Python analysis.

1
Open Power Query

Navigate to the 'Data' tab on the Excel ribbon, click on 'Get Data', select 'From Other Sources', and then choose 'From Web'.

2
Connect to the API

Enter the URL of your external API. If your API requires specific headers or API keys, select the 'Advanced' option to input them, then click 'OK'.

3
Load the Data

Once the Power Query Editor opens and previews your API data, click 'Close & Load' in the top-left corner to import the dataset directly into an Excel worksheet.

4
Analyze with Python

Select an empty cell, type =PY() to open the Python formula bar, and reference the imported Power Query table to begin your data analysis.

Use Power Query to Import Data First
Security Design: The inability to connect to the internet via Python in Excel is not a bug or a local firewall issue; it is a strict Microsoft security measure.
Free Microsoft Office alternative

Try WPS Office for Seamless Data Analysis and Spreadsheet Management

If Microsoft Excel's cloud container restrictions and complex add-ins disrupt your workflow, consider switching to WPS Office. It delivers powerful local spreadsheet processing, seamless format compatibility, and advanced data analysis tools without strict cloud-based limitations.

  1. 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
  2. 2. Install WPS Office: Run the downloaded file and follow the simple on-screen instructions to complete the installation.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to resume your data analysis instantly.
Conduct powerful local data analysis without being restricted by cloud container security blocksHighly compatible with Microsoft Excel (.xlsx, .xls, .csv) formatsLightweight architecture ensuring fast startup times and smooth performance on standard PCsBuilt-in advanced formulas, pivot tables, and charting toolsFree to download and use with a highly familiar ribbon interface
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a ProxyError when trying to use Python libraries like requests in Excel?

Python in Excel processes your code inside a highly secured Microsoft cloud environment. To prevent malicious activity and protect user data, this container explicitly blocks all outbound network connections, causing API requests to fail with ProxyError or 400 errors.

Can I change my firewall or antivirus settings to fix Python connection errors in Excel?

No. Changing your local Windows firewall, proxy configuration, or antivirus settings will not resolve this issue because the restriction is implemented at the cloud server level by Microsoft, not on your local machine.

Is there any way to perform live API data analysis using Python in Excel?

You cannot fetch live API data directly within the Python script itself. Instead, you must use Excel's built-in Power Query (Data > Get Data > From Web) to pull the live API data into your worksheet first, and then reference those spreadsheet cells using the =PY() function for your analysis.