requests 是 Python 的一个 HTTP 客户端库,跟 urllib,urllib2 类似,不过 requests 的优势在于使用简单,相同一个功能,用 requests 实现起来代码量要少很多。毕竟官方文档都很直白的说:
python 的标准库 urllib2 提供了大部分需要的 HTTP 功能,但是 API 太逆天了,一个简单的功能就需要一大堆代码。
所以,使用 requests 方便的多。
官方包下载地址: https://pypi.org/project/requests/#files
安装过程参考地址: https://www.cnblogs.com/Javi/p/9151629.html
复杂版: https://blog.csdn.net/echojosedream/article/details/52938136
参考pip在线安装
G:\Projects\github\hmac-auth-java-sdk\hmac-auth\jars>pip2 install requests
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Requirement already satisfied: requests in f:\python27\lib\site-packages (2.24.0)
Requirement already satisfied: idna<3,>=2.5 in f:\python27\lib\site-packages (from requests) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in f:\python27\lib\site-packages (from requests) (2020.6.20)
Requirement already satisfied: chardet<4,>=3.0.2 in f:\python27\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in f:\python27\lib\site-packages (from requests) (1.25.9)
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
下载离线安装包
https://files.pythonhosted.org/packages/da/67/672b422d9daf07365259958912ba533a0ecab839d4084c487a5fe9a5405f/requests-2.24.0.tar.gz
随后解压并准备安装
错误的离线安装命令
F:\Python27\python.exe F:\Programs\requests-2.24.0\requests-2.24.0\setup.py install
报错readme.md
找不到
G:\Projects\github\hmac-auth-java-sdk\hmac-auth\jars>F:\Python27\python.exe F:\Programs\requests-2.24.0\requests-2.24.0\setup.py install
Traceback (most recent call last):
File "F:\Programs\requests-2.24.0\requests-2.24.0\setup.py", line 64, in <module>
with open('README.md', 'r', 'utf-8') as f:
File "F:\Python27\lib\codecs.py", line 898, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: 'README.md'
意识到可能是使用了相对路劲去找上述问价,导致找不到,所以打算进入到setup.py
所在目录
正确的安装命令
cd F:\Programs\requests-2.24.0\requests-2.24.0\
F:\Programs\requests-2.24.0\requests-2.24.0>F:\Python27\python.exe setup.py install
running install
running bdist_egg
running egg_info
writing requirements to requests.egg-info\requires.txt
writing requests.egg-info\PKG-INFO
writing top-level names to requests.egg-info\top_level.txt
writing dependency_links to requests.egg-info\dependency_links.txt
reading manifest file 'requests.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'NOTICE'
warning: no files found matching 'requirements.txt'
writing manifest file 'requests.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\requests
copying requests\adapters.py -> build\lib\requests
copying requests\api.py -> build\lib\requests
copying requests\auth.py -> build\lib\requests
copying requests\certs.py -> build\lib\requests
copying requests\compat.py -> build\lib\requests
copying requests\cookies.py -> build\lib\requests
copying requests\exceptions.py -> build\lib\requests
copying requests\help.py -> build\lib\requests
copying requests\hooks.py -> build\lib\requests
copying requests\models.py -> build\lib\requests
copying requests\packages.py -> build\lib\requests
copying requests\sessions.py -> build\lib\requests
copying requests\status_codes.py -> build\lib\requests
copying requests\structures.py -> build\lib\requests
copying requests\utils.py -> build\lib\requests
copying requests\_internal_utils.py -> build\lib\requests
copying requests\__init__.py -> build\lib\requests
copying requests\__version__.py -> build\lib\requests
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\requests
copying build\lib\requests\adapters.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\api.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\auth.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\certs.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\compat.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\cookies.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\exceptions.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\help.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\hooks.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\models.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\packages.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\sessions.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\status_codes.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\structures.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\utils.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\_internal_utils.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\__init__.py -> build\bdist.win-amd64\egg\requests
copying build\lib\requests\__version__.py -> build\bdist.win-amd64\egg\requests
byte-compiling build\bdist.win-amd64\egg\requests\adapters.py to adapters.pyc
byte-compiling build\bdist.win-amd64\egg\requests\api.py to api.pyc
byte-compiling build\bdist.win-amd64\egg\requests\auth.py to auth.pyc
byte-compiling build\bdist.win-amd64\egg\requests\certs.py to certs.pyc
byte-compiling build\bdist.win-amd64\egg\requests\compat.py to compat.pyc
byte-compiling build\bdist.win-amd64\egg\requests\cookies.py to cookies.pyc
byte-compiling build\bdist.win-amd64\egg\requests\exceptions.py to exceptions.pyc
byte-compiling build\bdist.win-amd64\egg\requests\help.py to help.pyc
byte-compiling build\bdist.win-amd64\egg\requests\hooks.py to hooks.pyc
byte-compiling build\bdist.win-amd64\egg\requests\models.py to models.pyc
byte-compiling build\bdist.win-amd64\egg\requests\packages.py to packages.pyc
byte-compiling build\bdist.win-amd64\egg\requests\sessions.py to sessions.pyc
byte-compiling build\bdist.win-amd64\egg\requests\status_codes.py to status_codes.pyc
byte-compiling build\bdist.win-amd64\egg\requests\structures.py to structures.pyc
byte-compiling build\bdist.win-amd64\egg\requests\utils.py to utils.pyc
byte-compiling build\bdist.win-amd64\egg\requests\_internal_utils.py to _internal_utils.pyc
byte-compiling build\bdist.win-amd64\egg\requests\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\requests\__version__.py to __version__.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\not-zip-safe -> build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying requests.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
creating dist
creating 'dist\requests-2.24.0-py2.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing requests-2.24.0-py2.7.egg
creating f:\python27\lib\site-packages\requests-2.24.0-py2.7.egg
Extracting requests-2.24.0-py2.7.egg to f:\python27\lib\site-packages
Adding requests 2.24.0 to easy-install.pth file
Installed f:\python27\lib\site-packages\requests-2.24.0-py2.7.egg
Processing dependencies for requests==2.24.0
Searching for certifi==2020.6.20
Best match: certifi 2020.6.20
Adding certifi 2020.6.20 to easy-install.pth file
Using f:\python27\lib\site-packages
Searching for urllib3==1.25.9
Best match: urllib3 1.25.9
Adding urllib3 1.25.9 to easy-install.pth file
Using f:\python27\lib\site-packages
Searching for idna==2.10
Best match: idna 2.10
Adding idna 2.10 to easy-install.pth file
Using f:\python27\lib\site-packages
Searching for chardet==3.0.4
Best match: chardet 3.0.4
Adding chardet 3.0.4 to easy-install.pth file
Installing chardetect-script.py script to F:\Python27\Scripts
Installing chardetect.exe script to F:\Python27\Scripts
Using f:\python27\lib\site-packages
Finished processing dependencies for requests==2.24.0