小编dan*_*rak的帖子

urllib"模块对象不可调用"

这是我的第三个python项目,我收到了一条错误消息:'module object' is not callable.

我知道这意味着我正在错误地引用变量或函数.但是反复试验并没有帮助我解决这个问题.

import urllib

def get_url(url):
    '''get_url accepts a URL string and return the server response code, response headers, and contents of the file'''
    req_headers = {
        'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13',
        'Referer': 'http://python.org'}

    #errors here on next line
    request = urllib.request(url, headers=req_headers) # create a request object for the URL
    opener = urllib.build_opener() # create an opener object
    response = opener.open(request) # open a …
Run Code Online (Sandbox Code Playgroud)

python urllib python-3.x

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×1

python-3.x ×1

urllib ×1