Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

twitter - urllib.request in Python 2.7

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...