So, today, when I want to write up a simple test to post data to a web server, I imported lib urllib2 right away.
It usually works great… until you need something more than basic.
Apparently I need to set some cookie and set to the server. Let’s import cookiejar and cookie…
Why it throws an exception AttributeError: ‘SimpleCookie’ object has no attribute +’rfc2965’?
OK, let’s import DefaultCookiePolicy. Then I got hit by a missing domain attribute exception. “Do I need to use a lower level Cookie class to set the domain?”, I wonder. Try switching to Cookie and it throw this exception
1 2 3 4
At this point I said to myself: No, I am not going to figure out the 17 arguments. My test code is at this point in this dismal state:.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Instead of continuing banging my head against a wall, I recall reading about ‘requests’ module. Let give it a go.
Like magic, it is all I need. 2 lines.
It just works. Well done, requests!