类型错误:';模块';对象不可调用Python3
你好,我尝试运行run.py,但收到一条错误消息 Run.py类型错误:';模块';对象不可调用Python3,python,python-3.x,Python,Python 3.x,你好,我尝试运行run.py,但收到一条错误消息 Run.py from modules import HTTPHeaders site = "https://google.com" HTTPHeaders(site, _verbose=True) HTTPHeaders.py import dns import dns.resolver def HTTPHeaders(site, _verbose=None): if _verbose != None: try:
from modules import HTTPHeaders
site = "https://google.com"
HTTPHeaders(site, _verbose=True)
HTTPHeaders.py
import dns
import dns.resolver
def HTTPHeaders(site, _verbose=None):
if _verbose != None:
try:
r = http.request('GET', "http://"+site)
except:
pass
if (r.status == 200):
print("HTTP/1.1 200 OK")
else:
print(r.status)
try:
print("Content-Type : "+r.headers['Content-Type'])
except:
pass
try:
print("Server : "+r.headers['Server'])
except:
pass
try:
print("Set-Cookie : "+r.headers['Set-Cookie'])
except:
pass
我的错误:
TypeError: 'module' object is not callable
如何修复此错误?谢谢:)试试这个:
从模块导入HttpHeader
HTTPHeaders.HTTPHeaders(…)
您导入了模块本身,因此必须使用点符号访问函数
或者像这样导入函数:
from modules.HTTPHeaders导入HTTPHeaders
HttpHeader(…)
错误清楚地表明,您正在尝试调用导入的模块,这是不可能的。您打算做的是从这个模块中调用同名函数:HTTPHeaders.HTTPHeaders(site,\u verbose=True)
对不起,我更改了答案的文本。注意,现在它非常正确:)