I'm trying to read a website's content but I get an empty bytes object, b''.
import urllib3
from urllib3 import PoolManager
urllib3.disable_warnings()
https = PoolManager()
r = https.request('GET', 'https://minemen.club/leaderboards/practice/')
print(r.status)
print(r.read())
When I open the URL in a web browser I see the website, and r.status is 200 (success).
Why does r.read() not return the content?
What makes you think it is wrong? Try the following, you'll have much more output:
print(r.data)
Check HTTPResponse to see how to use the r object you got.
This is how urllib3.response.HTTPResponse.read is supposed to work.
It is explained for example here by one of the contributors to urllib3:
This is about documentation. You cannot use
read()by default, because by default all the content is consumed intodata. If you wantread()to work, you need to setpreload_content=Trueon the call tourlopen. Want to give that a try?
So you can simply use r.data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With