Python请求模块-找不到模块

时间:2018-10-09 07:58:50

标签: python pip python-requests

我的网站上有一个聊天框,我想使用requests库使用python脚本添加消息。

脚本如下:

import requests
import os
import random
import string
import json

random.seed = (os.urandom(1024))

url = 'http://subdomain.example.com/dir/filename.php'
names = json.loads(open('dir/filename.json').read())
messages = ['heyy', 'hoi', 'hai', 'he', 'haai', 'heyyy', 'hooi', 'heey', 'hee', 'hey', 'hallo']

for name in names:
    username = name.lower()
    message = random.choice(messages)
    params={
        'username': username,
        'message': message
    }
    r = requests.post(url, data=params)

当我在命令提示符下运行脚本时,它将返回以下内容:

Traceback (most recent call last):
  File "dir/filename.py", line 1, in <module>
    import requests
ImportError: No module named 'requests'

当我搜索此问题时,我发现我需要安装请求。我已经用这样的点子做过了:

pip install requests

当我尝试再次安装请求以确保其响应时:

Requirement already satisfied: requests in c:\users\user\appdata\local\programs\python\python36\lib\site-packages (2.19.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\usern\appdata\local\programs\python\python36\lib\site-packages (from requests) (2018.8.13)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in c:\users\user\appdata\local\programs\python\python36\lib\site-packages (from requests) (1.23)
Requirement already satisfied: idna<2.8,>=2.5 in c:\users\user\appdata\local\programs\python\python36\lib\site-packages (from requests) (2.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\user\appdata\local\programs\python\python36\lib\site-packages (from requests) (3.0.4)
You are using pip version 18.0, however version 18.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

1 个答案:

答案 0 :(得分:0)

我的脚本位于我的本地主机中。(不在python的安装位置)我将文件移至C:/ python34,并且脚本执行了所需的操作。