Fix Python in Excel Cannot Connect to APIs or the Internet
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.

- 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.
Verify that your computer has a stable, active internet connection and that you are signed into your Microsoft 365 account with an active license.
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.
Navigate to the 'Data' tab on the Excel ribbon, click on 'Get Data', select 'From Other Sources', and then choose 'From Web'.
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'.
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.
Select an empty cell, type =PY() to open the Python formula bar, and reference the imported Power Query table to begin your data analysis.

Force an Account License Update
If you are experiencing unexpected behavior or believe your Microsoft 365 subscription is not syncing correctly with the cloud container, forcing a license update can help.
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. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the downloaded file and follow the simple on-screen instructions to complete the installation.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheets and open your existing Excel workbooks to resume your data analysis instantly.

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.




