如何解决TypeError: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)
,
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请求的情况下
r = http.request('POST','http://httpbin.org/post',fields={'hello': 'world'})
,
如果您要向URL发出GET
请求,则可以使用requests
模块
import requests
response = requests.get('https://shadowhosting.net/')
print(response.text)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。