Python 2.7 中的 urllib.request [英] urllib.request in Python 2.7

查看:37
本文介绍了Python 2.7 中的 urllib.request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在 Python 3.1 中使用 urllib.request 模块.但是当我使用 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'.

我认为这个错误是因为 urllib 中没有 Python 2.7 的请求模块.因为我需要使用 tweepy 我必须坚持使用 Python 2.7,因为 tweepy 不支持 Python 3.

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.

那么如何在 Python 2.7 中使用 urllib.request 模块?

So how I can use urllib.request module in Python 2.7?

推荐答案

use <代码>urllib2.urlopen

这篇关于Python 2.7 中的 urllib.request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆