Reputation: 33
New to python so give me a break if I've missed something stupid or it's been answered somewhere else.
Currently working through the 'Python Challenges'. I'm on challenge 5 and attempting to use the Pickle module through passing in some pickled text. I have got it working using the urllib as follows ...
import pickle
from urllib.request import urlopen
page = "http://www.pythonchallenge.com/pc/def/banner.p"
raw = urlopen(page)
pick = pickle.load(raw)
print(raw)
print(pick)
However, I'm trying to get it working with the requests library using
raw = requests.get(page).content
but when then passed into pickle.load()
, I receive the error:
TypeError: file must have 'read' and 'readline' attributes
Any help would be hugely appreciated!
Upvotes: 0
Views: 1309
Reputation: 21
It's my first answer on stackoverflow. I checked this 3 times lol
But yeah, this is in the requests doc itself.
import pickle
import requests
def main():
r=requests.get('http://www.pythonchallenge.com/pc/def/banner.p',stream='True')
print(pickle.load(r.raw))
if __name__=='__main__':
main()
Upvotes: 2