AttributeError: 'module' object has no attribute 'request'

前端 未结 4 1649
灰色年华
灰色年华 2021-01-30 02:02

When I run the following code in Python 3.3:

import urllib
tempfile = urllib.request.urlopen(\"http://yahoo.com\")

I get the following error:

4条回答
  •  误落风尘
    2021-01-30 02:30

    The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.


    Import urllib.request instead of urllib.

    import urllib.request
    

提交回复
热议问题