Troubleshooting "python requests not recognized by pylance"

Feb 3, 2024 ยท 2 min read

When working with Python in Visual Studio Code, you may come across an error like "requests is not accessed" reported by the Pylance language server. This can be frustrating, since requests is a very common Python library. Here are some things to check to resolve this issue.

The root cause is that Pylance does not have full knowledge of the requests library when it analyzes your code. Pylance relies on stub files to determine what modules, functions, and variables are available. If it's missing stubs for requests, it will think import requests or requests.get are invalid.

Ensure Pylance is installed

First, make sure Pylance is actually installed in VS Code. Open the extensions sidebar, search for "pylance," and verify it is enabled. If not, install the extension from the marketplace. Pylance comes bundled with Python support in recent versions of VS Code.

Check your Python interpreter

Next, check that your selected Python interpreter is supported by Pylance. Click on the Python version in the bottom bar and ensure it points to a CPython 3.6+ install that Pylance can analyze. If you use virtual environments, activate the venv first.

Allow remote stub downloads

Finally, make sure Pylance has permissions to download stub files from its remote repository. Go to File > Preferences > Settings and search for "pylance stub." Ensure the "Stub Download" setting does not block downloads over the internet.

After checking these points, close and reopen your Python file to restart Pylance, or simply try running/building your program. This should allow Pylance to grab the latest stubs containing requests and resolve that error.

The key is making sure Pylance has access to stub files over the network so it can properly analyze third-party libraries like requests.

Browse by tags:

Browse by language:

The easiest way to do Web Scraping

Get HTML from any page with a simple API call. We handle proxy rotation, browser identities, automatic retries, CAPTCHAs, JavaScript rendering, etc automatically for you


Try ProxiesAPI for free

curl "http://api.proxiesapi.com/?key=API_KEY&url=https://example.com"

<!doctype html>
<html>
<head>
    <title>Example Domain</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
...

X

Don't leave just yet!

Enter your email below to claim your free API key: