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

Viewed 3040

I'm getting deep into Python and was going through urllib3's docs. Tried running the code but seems like it's not working the way it's expected to. My code is

import urllib3

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

And the error I get is

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

I tried swapping place but still not working. I'm following the very beginning of the documentation(User Guide) For reference - https://urllib3.readthedocs.io/en/latest/user-guide.html

3 Answers

It's a typo forgot the parenthesis to create an object:

t = urllib3.PoolManager()

Add them and it shall work like magic:

import urllib3

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

if you want to make GET request to URL then you can use requests module

import requests

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

The docs at https://urllib3.readthedocs.io/en/latest/user-guide.html says :

    import urllib3

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

OR in case of POST request

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