类型错误:request() 缺少 1 个必需的位置参数:urllib3 中的"url"



我正在深入了解Python,并正在浏览urllib3的文档。尝试运行代码,但似乎没有按预期方式运行。我的代码是

import urllib3
t = urllib3.PoolManager
test = t.request('GET', 'https://shadowhosting.net/')
print(test.data)

我得到的错误是

TypeError: request() missing 1 required positional argument: 'url'

我试着换个地方,但还是没用。我遵循文档的开头部分(用户指南(供参考-https://urllib3.readthedocs.io/en/latest/user-guide.html

这是一个打字错误,忘记了创建对象的括号:

t = urllib3.PoolManager()

添加它们,它将像魔术一样工作:

import urllib3
t = urllib3.PoolManager()
test = t.request('GET', 'https://shadowhosting.net/')
print(test.data)

如果您想向URL发出GET请求,则可以使用requests模块

import requests
response = requests.get('https://shadowhosting.net/')
print(response.text)

https://urllib3.readthedocs.io/en/latest/user-guide.html说:

import urllib3
http = urllib3.PoolManager()    //You were missing this paranthesis
r = http.request('GET', 'http://httpbin.org/robots.txt')

POST请求时的OR

r = http.request('POST','http://httpbin.org/post', fields={'hello': 'world'})

最新更新