I can use urllib.request module with Python 3.1. But when I execute the same program using Python 2.7, an error comes along the lines of;
AttributeError: 'module' object has no attribute 'request'.
I believe this error is because theres no request module in urllib for Python 2.7. Because I need to use tweepy i'll have to stick with Python 2.7 since tweepy does not support Python 3.
So how I can use urllib.request module in Python 2.7?
The urllib. request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. See also. The Requests package is recommended for a higher-level HTTP client interface.
The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.
It is also possible to use six
module to make code for both python2 & python3:
from six.moves import urllib # ... result = urllib.request.urlopen(url)
Use urllib2.urlopen
for Python 2.
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