1

I can't import request module. It gives an error while importing and the error states that it cannot find the module. I installed the module but still facing the same issue. I check with (pip list) command and the request module seems to be registered. I also updated the pip command. the error still persists.

importing the requests library

import requests # defining the api-endpoint API_ENDPOINT = "http://pastebin.com/api/api_post.php" # your API key here API_KEY = "XXXXXXXXXXXXXXXXX" # your source code here source_code = ''' print("Hello, world!") a = 1 b = 2 print(a + b) ''' # data to be sent to api data = {'api_dev_key':API_KEY, 'api_option':'paste', 'api_paste_code':source_code, 'api_paste_format':'python'} # sending post request and saving response as response object r = requests.post(url = API_ENDPOINT, data = data) # extracting response text pastebin_url = r.text print("The pastebin URL is:%s"%pastebin_url) 
1
  • Are you inside of an environment? Commented Aug 3, 2021 at 13:40

1 Answer 1

4

Make sure you have installed it for the correct version of python. If you have many python installations on your system, it can get difficult. So if you are running your script with a specific version, ex. python 3.8, you will have to install requests for that version. In this example, run

python3.8 -m pip install requests 

Try python2 or python3 too with the -m option.

Also, if you're on windows, use the py python launcher.

Like:

py -3 -m pip install requests 

If you're inside a virtual environment or running docker, then the story is completely different...

Please refer to this: Dealing with multiple Python versions and PIP?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.