python-3.x - `没有名为'urllib2'的模块-我如何在Python中使用它,以便我可以提出请求
问题描述
Python新手,只是不确定如何为python做什么
我想使用urllib2
-Request
拨打电话 我该怎么做,例如在 repl 中。我想不出正确的方法
$ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib2 import Request, urlopen, URLerror, HTTPerror
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib2'
>>> from urllib2 import Request, urlopen, URLerror, HTTPerror
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib2'
>>> import Request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Request'
>>> import urllib2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib2'
>>>
...
req = Request(URL, json_message) #(URL and json_message defined but not shown here)
...
我是否必须将 urllib2 单独安装到系统中?就像我说的只是一个不知道步骤和语法的 Python 新手。谢谢!
我正在使用的示例有
from urllib2 import Request, urlopen, URLError, HTTPError
然后使用Request(...
,但是当我在 python3 repl 中尝试时,我得到了
$ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib2 import Request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib2'
>>>
解决方案
推荐阅读
- mongodb - Mongodb 聚合匹配和分组文档,附加检查
- java - 给定 curl 代码的 Java 等效 HTTP post 方法
- julia - 使用 Gadfly 绘制多个数据文件
- kotlin - 期望在 Getter 中声明成员
- python - 将 docker 用于 Celery Task +Rabbitmq 不适用于 python 3.7
- c# - linq中按时间顺序排序的日期时间
- here-api - 离线使用 SDK 时出错:calculateRoute 返回 GRAPH_DISCONNECTED
- hyperledger-fabric - 无法在 Mac OS 上启动 Fabric,startFabric.sh 给出守护程序错误
- mysql - 是否可以获得我们正在删除的特定列值
- angular - Angular 应用程序中 Font Awesome 字体的 CORS 错误