已有184人关注
网络爬虫
还有0人有此问题
发表在Python图书答疑 2022-12-16 《零基础学Python》
是否精华
版块置顶:

import urllib.request

response = urllib.request.urlopen('http://www.baidu.com/')

print(response.read().decode('utf-8'))

当我运行上面代码为什么出现下面的情况:

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.


----------------------------------------

Unhandled exception in user code execution server!'

Thread: SockThread

IDLE Client Address: ('127.0.0.1', 51801)

Request: <socket.socket fd=700, family=2, type=1, proto=0, laddr=('127.0.0.1', 52150), raddr=('127.0.0.1', 51801)>


Traceback (most recent call last):

  File "C:\Python\Python311\Lib\socketserver.py", line 317, in _handle_request_noblock

    self.process_request(request, client_address)

  File "C:\Python\Python311\Lib\socketserver.py", line 348, in process_request

    self.finish_request(request, client_address)

  File "C:\Python\Python311\Lib\socketserver.py", line 361, in finish_request

    self.RequestHandlerClass(request, client_address, self)

  File "C:\Python\Python311\Lib\idlelib\rpc.py", line 514, in __init__

    socketserver.BaseRequestHandler.__init__(self, sock, addr, svr)

  File "C:\Python\Python311\Lib\socketserver.py", line 755, in __init__

    self.handle()

  File "C:\Python\Python311\Lib\idlelib\run.py", line 532, in handle

    import pydoc # import must be done here to capture i/o binding

    ^^^^^^^^^^^^

  File "C:\Python\Python311\Lib\pydoc.py", line 73, in <module>

    import urllib.parse

  File "C:\Python\Python311\urllib.py", line 1, in <module>

    import urllib.request

ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package


*** Unrecoverable, server exiting!


Users should never see this message; it is likely transient.

If this recurs, report this with a copy of the message

and an explanation of how to make it repeat.

----------------------------------------


分享到:
精彩评论 1
小禾斗
学分:7338 LV13
TA的每日心情
奋斗
2017-04-21 14:00:25
2022-12-16
沙发

没有安装这个模块,在cmd命令窗口中用pip install安装这个模块之后再执行

首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照