For the standard urllib.request object obtained as follows:
req = urllib.urlopen('http://example.com')
If I read its contents through req.read() , then the request object will be empty.
Unlike regular file objects, the request object does not have a seek method, as I am sure these are great reasons.
However, in my case, I have a function, and I want it to make certain definitions about the request and then return that request βunharmedβ so that it can be read again.
I understand that one option is to re-query. But I would like to be able to avoid multiple HTTP requests for the same URL and content.
The only alternative I can think of is that the function returns a tuple of the extracted content and the request object, with the understanding that everything that calls this function will need to get the content in this way.
Is this my only option?
source share